Bugfix: spec-compliant behaviour for non-nullable types with default values.#2573
Merged
bbakerman merged 2 commits intographql-java:masterfrom Dec 27, 2021
Merged
Conversation
added 2 commits
October 5, 2021 14:04
… in the query for non-nullable argument with default argument value specified in the schema.
Contributor
|
Related to this, here's a test case in graphql-js for this behavior |
bbakerman
reviewed
Oct 9, 2021
| schemaDefaultValue = (Value) schemaDefault.get().getValue(); | ||
| } else if (schemaDefault.isPresent() && schemaDefault.get().isSet()) { | ||
| schemaDefaultValue = ValuesResolver.valueToLiteral(schemaDefault.get(), expectedType); | ||
| } |
Member
There was a problem hiding this comment.
@andimarek - can you please double check that the argument get value calls here are correct in the new regime for reading args values.
Member
There was a problem hiding this comment.
You can simplify the code here: there is a method in ValuesResolver ValuesResolver.valueToLiteral which takes care of converting it fo you.
Contributor
Author
There was a problem hiding this comment.
Hey @andimarek! I believe that's the exact method I'm using on line 67 there. Am I missing something else?
bbakerman
approved these changes
Oct 9, 2021
andimarek
requested changes
Dec 20, 2021
Member
andimarek
left a comment
There was a problem hiding this comment.
Thanks for that. Please have a look a the comment I left.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.