-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix triple nested enum validation error #2570
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
Merged
bbakerman
merged 4 commits into
graphql-java:master
from
dondonz:2560-enum-invalid-error
Oct 7, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package graphql.execution | ||
|
|
||
| import graphql.ErrorType | ||
| import graphql.ExecutionInput | ||
| import graphql.GraphQLException | ||
| import graphql.TestUtil | ||
| import graphql.language.Argument | ||
|
|
@@ -12,6 +14,7 @@ import graphql.language.NonNullType | |
| import graphql.language.NullValue | ||
| import graphql.language.ObjectField | ||
| import graphql.language.ObjectValue | ||
| import graphql.language.SourceLocation | ||
| import graphql.language.StringValue | ||
| import graphql.language.TypeName | ||
| import graphql.language.Value | ||
|
|
@@ -548,4 +551,123 @@ class ValuesResolverTest extends Specification { | |
| def error = thrown(NonNullableValueCoercedAsNullException) | ||
| error.message == "Argument 'arg' has coerced Null value for NonNull type 'inputObject!'" | ||
| } | ||
| } | ||
|
|
||
| def "invalid enum error message is not nested and contains source location - issue 2560"() { | ||
| when: | ||
| def graphQL = TestUtil.graphQL(''' | ||
| enum PositionType { | ||
| MANAGER | ||
| DEVELOPER | ||
| } | ||
|
|
||
| input PersonInput { | ||
| name: String | ||
| position: PositionType | ||
| } | ||
|
|
||
| type Query { | ||
| name: String | ||
| } | ||
|
|
||
| type Mutation { | ||
| updatePerson(input: PersonInput!): Boolean | ||
| } | ||
| ''').build() | ||
|
|
||
| def mutation = ''' | ||
| mutation UpdatePerson($input: PersonInput!) { | ||
| updatePerson(input: $input) | ||
| } | ||
| ''' | ||
|
|
||
| def executionInput = ExecutionInput.newExecutionInput() | ||
| .query(mutation) | ||
| .variables([input: [name: 'Name', position: 'UNKNOWN_POSITION'] ]) | ||
| .build() | ||
|
|
||
| def executionResult = graphQL.execute(executionInput) | ||
|
|
||
| then: | ||
| executionResult.data == null | ||
| executionResult.errors.size() == 1 | ||
| executionResult.errors[0].errorType == ErrorType.ValidationError | ||
| executionResult.errors[0].message == 'Variable \'input\' has an invalid value: Invalid input for Enum \'PositionType\'. No value found for name \'UNKNOWN_POSITION\'' | ||
|
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. For the record - Groovy has 4 types of comments if you find yourself using `'input' - just swap quotes |
||
| executionResult.errors[0].locations == [new SourceLocation(2, 35)] | ||
| } | ||
|
|
||
| def "invalid boolean coercing parse value error message is not nested and contains source location - issue 2560"() { | ||
| when: | ||
| def graphQL = TestUtil.graphQL(''' | ||
| input PersonInput { | ||
| name: String | ||
| hilarious: Boolean | ||
| } | ||
|
|
||
| type Query { | ||
| name: String | ||
| } | ||
|
|
||
| type Mutation { | ||
| updatePerson(input: PersonInput!): Boolean | ||
| } | ||
| ''').build() | ||
|
|
||
| def mutation = ''' | ||
| mutation UpdatePerson($input: PersonInput!) { | ||
| updatePerson(input: $input) | ||
| } | ||
| ''' | ||
|
|
||
| def executionInput = ExecutionInput.newExecutionInput() | ||
| .query(mutation) | ||
| .variables([input: [name: 'Name', hilarious: 'sometimes'] ]) | ||
| .build() | ||
|
|
||
| def executionResult = graphQL.execute(executionInput) | ||
|
|
||
| then: | ||
| executionResult.data == null | ||
| executionResult.errors.size() == 1 | ||
| executionResult.errors[0].errorType == ErrorType.ValidationError | ||
| executionResult.errors[0].message == 'Variable \'input\' has an invalid value: Expected type \'Boolean\' but was \'String\'.' | ||
| executionResult.errors[0].locations == [new SourceLocation(2, 35)] | ||
| } | ||
|
|
||
| def "invalid float coercing parse value error message is not nested and contains source location - issue 2560"() { | ||
| when: | ||
| def graphQL = TestUtil.graphQL(''' | ||
| input PersonInput { | ||
| name: String | ||
| laughsPerMinute: Float | ||
| } | ||
|
|
||
| type Query { | ||
| name: String | ||
| } | ||
|
|
||
| type Mutation { | ||
| updatePerson(input: PersonInput!): Boolean | ||
| } | ||
| ''').build() | ||
|
|
||
| def mutation = ''' | ||
| mutation UpdatePerson($input: PersonInput!) { | ||
| updatePerson(input: $input) | ||
| } | ||
| ''' | ||
|
|
||
| def executionInput = ExecutionInput.newExecutionInput() | ||
| .query(mutation) | ||
| .variables([input: [name: 'Name', laughsPerMinute: 'none'] ]) | ||
| .build() | ||
|
|
||
| def executionResult = graphQL.execute(executionInput) | ||
|
|
||
| then: | ||
| executionResult.data == null | ||
| executionResult.errors.size() == 1 | ||
| executionResult.errors[0].errorType == ErrorType.ValidationError | ||
| executionResult.errors[0].message == 'Variable \'input\' has an invalid value: Expected type \'Float\' but was \'String\'.' | ||
| executionResult.errors[0].locations == [new SourceLocation(2, 35)] | ||
| } | ||
| } | ||
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.
The fundamental change is to move the
CoercingParseValueExceptioncatch one function earlier in the chain, toexternalValueToInternalValueForVariables.Although it appears many lines are changing, it's mostly only indentation for the try catch block.
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 rationale for moving the catch: the source location is available here, whereas it is not passed down to the next function
externalValueToInternalValue.