-
Notifications
You must be signed in to change notification settings - Fork 96
GraphQLID support #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQLID support #110
Conversation
Added type annotation @GraphQLID
|
What happens if I put |
| } | ||
|
|
||
| @Test | ||
| public void id() throws NoSuchMethodException, NoSuchFieldException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaningfull name please. What does this test do?
| Field idIntegerField = DefaultTypeFunctionTest.class.getField("idIntegerField"); | ||
| Field idIntField = DefaultTypeFunctionTest.class.getField("idIntField"); | ||
|
|
||
| assertEquals(instace.buildType(idStringMethod.getReturnType(), idStringMethod.getAnnotatedReturnType()), GraphQLID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alot of asserts. Maybe better to split to few tests
|
If you put |
|
From the official docs:
So, I think there should be only 1 ID per object |
|
On second thought, the uniqueness is of the value of the id, not the id itself, so it is fine by me that an object can have 2 ID's |
| @Override | ||
| public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) { | ||
| return annotatedType != null | ||
| && (aClass == Integer.class || aClass == int.class || aClass == String.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you restrict the ID to be a String or an int? What If I want my ID to be a costum type? (UUID for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the spec defines GraphQLID to be integer/string, it can only accept those 2 types:
When expected as an input type, any string (such as "4") or integer (such as 4) input value should be coerced to ID as appropriate for the ID formats a given GraphQL server expects. Any other input value, including float input values (such as 4.0), must raise a query error indicating an incorrect type.
| public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) { | ||
| return annotatedType != null | ||
| && (aClass == Integer.class || aClass == int.class || aClass == String.class) | ||
| && (annotatedType.getAnnotation(GraphQLID.class) != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use getAnnotation(GraphQLID.class) to verify that the annotation is present. It may throw a NullPointerExeception. You should use instead isAnnotationPresent(GraphQLID.class).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, thanx :)
Adds support for GraphQLID (exists in graphql-java).
Adds an annotation @GraphQLID you can put before a method/field with String/Integer/int type.
For example:
private @GraphQLID String id;It will be represented as an ID scalar.
Fixes issue #71