-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bugfix: spec-compliant behaviour for non-nullable types with default values. #2573
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
Bugfix: spec-compliant behaviour for non-nullable types with default values. #2573
Conversation
… in the query for non-nullable argument with default argument value specified in the schema.
|
Related to this, here's a test case in graphql-js for this behavior |
| schemaDefaultValue = (Value) schemaDefault.get().getValue(); | ||
| } else if (schemaDefault.isPresent() && schemaDefault.get().isSet()) { | ||
| schemaDefaultValue = ValuesResolver.valueToLiteral(schemaDefault.get(), expectedType); | ||
| } |
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 - can you please double check that the argument get value calls here are correct in the new regime for reading args values.
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 can simplify the code here: there is a method in ValuesResolver ValuesResolver.valueToLiteral which takes care of converting it fo you.
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.
Hey @andimarek! I believe that's the exact method I'm using on line 67 there. Am I missing something else?
andimarek
left a comment
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.
Thanks for that. Please have a look a the comment I left.
Hi folks!
Problem
Graphql-java currently fails the document validation for queries that use nullable types for non-nullable schema field arguments with default values. As per spec:
Here's a discussion from 2018 where this change to the spec was adopted: graphql/graphql-spec#418.
Motivating example:
Schema:
Query:
This is expected to pass the validation, but currently fails:
ValidationError{validationErrorType=VariableTypeMismatch, queryPath=[hello], message=Validation error of type VariableTypeMismatch: Variable type 'Boolean' doesn't match expected type 'Boolean!' @ 'hello', locations=[SourceLocation{line=3, column=25}], description='Variable type 'Boolean' doesn't match expected type 'Boolean!''}Solution
This patch fixes the issue by extracting the schema-defined default value for the argument (if present), and checks that in the
VariablesTypeMatcheralong with the original check. This also adds a regression test to exercise this fix, similar to the test in the reference GraphQL implementation.