-
Notifications
You must be signed in to change notification settings - Fork 96
Keep all output types in registry, move type resolution from TypeFunctions to GraphQLAnnotations #94
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
Conversation
I have added a new commit for also handling input types, which will solve issue #90 . |
Any thoughts about this PR ? It solves a lot of different issues, it would be nice to discuss about it |
I would love this PR to be merged into the master, thank you for the work @tdraier. Any chance that happens soon ? |
Unfortunately I cannot tell you, I don't see much activity here. Hopefully we will get some news after the holidays .. ? |
It will take time to merge it, because it will take time for me to look make a good code review. but in general: don't you think GraphQLAnnotations is too big? how about refactor the code to make it more SOLID and readable? |
Completely agree, the GraphQLAnnotations class could be split in smaller parts. I did not want to rewrite everything is this pull request to try to keep it understandable - at least you can see what has been changed (mainly, keeping types in a centralised repository to avoid recreating the same type many times, which already implies a lot of refactoring). I understand the review can take time, don't hesitate to ask me if some points are unclear |
I agree that it would be nice to refactor the code but the functionality in this PR is really useful. I would recommend that we first merge this and then eventually in a second phase refactor. This will also make the merging process easier. |
bd14def
to
23972c6
Compare
Rebased to master to solve conflicts |
Can you please fix the failing test? |
typeRegistry.put(inputObjectType.getName(), inputObjectType); | ||
return inputObjectType; | ||
} else if (graphQLType instanceof GraphQLList) { | ||
return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix)); |
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.
It looks like you dont handle recursive lists, like List<List>
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.
the getInputObject is recursive, so List of List should be handled. I've added a unit test for that and it works. Do you have a code sample that does not work as expected ?
I have tried, using your code, to create a Query field that gets as an argument list of input type, and it throws an exception ("Introspection must provide input type for arguments.") |
"Introspection must provide input type for arguments." is an error from graphql-java - it might be that you are using at some point the same class for input and output. Since all types are stored in the registry, it's not possible anymore to use a class for both inputs and outputs - it must be different classes. So you probably got an OutputType instead of an InputType and used it as an argument, hence the exception. Do you have a code sample to reproduce this ? |
Well I have this InputClass, I only use it as an argument to a query. While this works:
The following code will produce "Introspection must provide input type for arguments.":
|
I've locally added your fields to the TestObjectList in the unit test but unfortunately did not manage to see your error. The schema is correctly created, I got this from the SchemaPrinter :
|
Although it is not recommended to use the same class as input and output, It is not our responsibility to enforce that |
Actually, according to the specs ( http://facebook.github.io/graphql/October2016/#sec-Type-System ), "All types within a GraphQL schema must have unique names.". It's absolutely not possible to have an input and an output type with the same type name. Graphql-java uses internally a unique string->type map for all types, input and outputs. |
but since a prefix of "input" is added to input types, isnt it ok to use the same class? |
But that's why we have the prefix "input" in |
The main question is "Does the mapping between java classes and graphql types is one to one? I think that the mapping shouldn't be one to one, so one class can represents more than one graphql type (and then we use the "input" prefix) |
You're right, an "input" prefix was added, but I actually removed it in the branch. I don't remember why exactly (there was probably some issues to find it back in the registry), but I can try to restore it. Having the prefix solves the issue. The mapping is maybe not one class to one type, but at most it will be one class to two types. |
So please restore it and resolve the conflicts, and I will merge it |
…tions to GraphQLAnnotations
…tion to choose if the returned type should be an input type
ebbc899
to
9a5cccb
Compare
I did restore the input prefix - it actually makes the code a little cleaner, especially in DefaultTypeFunction (I had a not very nice try-catch to determine if the type was input or output). However I had to replace the typeName parameter (which was actually not used) by a boolean indicating if we want an input or an output. |
Here's some change proposition related to the issue : #92 . The changes are significant but should not be breaking, api compatibility is kept and all tests pass.
Basically the idea is :
One change was required in the tests : cleanup the registry before executing any new test, as all object types are now kept here and we have many tests defining different ObjectType with the same name.