-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Exclude custom scalar literals from validation #1157
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
martinbonnin
wants to merge
1
commit into
values-of-correct-type-variables
from
martin/no-validation-for-custom-scalar-literals
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1306,9 +1306,10 @@ fragment resourceFragment on Resource { | |||||||||||||||||
|
||||||||||||||||||
- For each literal Input Value {value} in the document: | ||||||||||||||||||
- Let {type} be the type expected in the position {value} is found. | ||||||||||||||||||
- {value} must be coercible to {type} (with the assumption that any | ||||||||||||||||||
{variableUsage} nested within {value} will represent a runtime value valid | ||||||||||||||||||
for usage in its position). | ||||||||||||||||||
- If {type} is not a custom scalar type: | ||||||||||||||||||
- {value} must be coercible to {type} (with the assumption that any | ||||||||||||||||||
{variableUsage} nested within {value} will represent a runtime value valid | ||||||||||||||||||
for usage in its position). | ||||||||||||||||||
|
||||||||||||||||||
**Explanatory Text** | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -1324,6 +1325,11 @@ algorithm ensures runtime values for variables coerce correctly. Therefore, for | |||||||||||||||||
the purposes of the "coercible" assertion in this validation rule, we can assume | ||||||||||||||||||
the runtime value of each {variableUsage} is valid for usage in its position. | ||||||||||||||||||
|
||||||||||||||||||
Note: Custom scalar coercion rules are not always available when validating a | ||||||||||||||||||
document and custom scalar literal values are excluded from this validation. If | ||||||||||||||||||
a custom scalar literal value cannot be coerced, it will raise an execution | ||||||||||||||||||
error. | ||||||||||||||||||
Comment on lines
+1328
to
+1331
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.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
The type expected in a position includes the type defined by the argument a | ||||||||||||||||||
value is provided for, the type defined by an input object field a value is | ||||||||||||||||||
provided for, and the type of a variable definition a default value is provided | ||||||||||||||||||
|
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.
Here we're punting the problem to execution for custom scalars, specifically to CoerceArgumentValues(), and specifically to these lines in the algorithm:
In GraphQL.js this aligns with the
parseLiteral
call. In particular, in the case of variable references inside of literals for custom scalars such as the JSON scalar, this results in parseLiteral being called twice and yielding two different values, one that has no variables (during validation) and one that does (during execution). So I understand the desire to skip it.However, I think there's value in performing validation of the literal if you can, even for custom scalars, so I'd encourage incorporation of an addition:
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.
I understand the intent there but I don't think any implementation is doing this at the moment?
I like validation to be a pure function of
typeSystemDefinitions + executableDefinition
, i.e. it operates purely on build time artifacts. Recommending something else opens a new door which I'd rather keep closed, especially if we have no proof that people need this actively.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.
GraphQL.js currently validates custom scalars via
parseLiteral
via validation if I'm not mistaken (this is evidenced byparseLiteral
being called twice), so I'd expect any implementation based on GraphQL.js to do this.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.
Here's proof using GraphQL.js that shows GraphQL.js does this. Run it with
node script.mjs
and you will see the"string"
value is not accepted for the custom scalar, but thetrue
value is. Custom scalars are just scalars in GraphQL.js.script.mjs