-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ensure NormalizedQueryTreeFactory handles mutations and subscriptions #2126
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -853,6 +853,113 @@ type Dog implements Animal{ | |
| coordinatesToNormalizedFields[coordinates("Foo", "subFoo")].size() == 2 | ||
| } | ||
|
|
||
| def "handles mutations"() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another test for Subscriptions would be awesome, but Mutation is good enough. |
||
| String schema = """ | ||
| type Query{ | ||
| animal: Animal | ||
| } | ||
|
|
||
| type Mutation { | ||
| createAnimal: Query | ||
| } | ||
|
|
||
| type Subscription { | ||
| subscribeToAnimal: Query | ||
| } | ||
|
|
||
| interface Animal { | ||
| name: String | ||
| friends: [Friend] | ||
| } | ||
|
|
||
| union Pet = Dog | Cat | ||
|
|
||
| type Friend { | ||
| name: String | ||
| isBirdOwner: Boolean | ||
| isCatOwner: Boolean | ||
| pets: [Pet] | ||
| } | ||
|
|
||
| type Bird implements Animal { | ||
| name: String | ||
| friends: [Friend] | ||
| } | ||
|
|
||
| type Cat implements Animal{ | ||
| name: String | ||
| friends: [Friend] | ||
| breed: String | ||
| } | ||
|
|
||
| type Dog implements Animal{ | ||
| name: String | ||
| breed: String | ||
| friends: [Friend] | ||
| } | ||
|
|
||
| schema { | ||
| query: Query | ||
| mutation: Mutation | ||
| subscription: Subscription | ||
| } | ||
|
|
||
| """ | ||
| GraphQLSchema graphQLSchema = TestUtil.schema(schema) | ||
|
|
||
| String mutation = """ | ||
| mutation TestMutation{ | ||
| createAnimal { | ||
| animal { | ||
| name | ||
| otherName: name | ||
| ... on Cat { | ||
| name | ||
| friends { | ||
| ... on Friend { | ||
| isCatOwner | ||
| } | ||
| } | ||
| } | ||
| ... on Bird { | ||
| friends { | ||
| isBirdOwner | ||
| } | ||
| friends { | ||
| name | ||
| } | ||
| } | ||
| ... on Dog { | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
|
|
||
| assertValidQuery(graphQLSchema, mutation) | ||
|
|
||
| Document document = TestUtil.parseQuery(mutation) | ||
|
|
||
| NormalizedQueryTreeFactory dependencyGraph = new NormalizedQueryTreeFactory(); | ||
| def tree = dependencyGraph.createNormalizedQuery(graphQLSchema, document, null, [:]) | ||
| def printedTree = printTree(tree) | ||
|
|
||
| expect: | ||
| printedTree == ['Mutation.createAnimal: Query (conditional: false)', | ||
| 'Query.animal: Animal (conditional: false)', | ||
| 'Bird.name: String (conditional: true)', | ||
| 'Cat.name: String (conditional: true)', | ||
| 'Dog.name: String (conditional: true)', | ||
| 'otherName: Bird.name: String (conditional: true)', | ||
| 'otherName: Cat.name: String (conditional: true)', | ||
| 'otherName: Dog.name: String (conditional: true)', | ||
| 'Cat.friends: [Friend] (conditional: true)', | ||
| 'Friend.isCatOwner: Boolean (conditional: false)', | ||
| 'Bird.friends: [Friend] (conditional: true)', | ||
| 'Friend.isBirdOwner: Boolean (conditional: false)', | ||
| 'Friend.name: String (conditional: false)'] | ||
| } | ||
|
|
||
| private void assertValidQuery(GraphQLSchema graphQLSchema, String query) { | ||
| GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We use normally
Assert.assertShouldNeverHappenhere.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.
Hello Andreas,
Assert.assertShouldNeverHappenseems to not work here as compiler complains thatrootTypeis not initialized. And it looks like a good compile time check.Can we commit this (as original author seems to be not available) as is? And replace this exception with something like
in a follow up PR?
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.
@andimarek thoughts?
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.
+1 to commit, I'm hitting this issue as well. How about using a return statement to get rid of the initialization issue: