-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Clarify 'Values of Correct Type' rule relates to literals #1118
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
df483ec
to
7fe1b5a
Compare
@graphql/tsc I would love to get your input on this change. |
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.
Good clarification 👍
Left a few additional questions that arose while doing the review but the PR in itself is an improvement from the current state and I support merging it.
@@ -1304,15 +1304,26 @@ fragment resourceFragment on Resource { | |||
|
|||
**Formal Specification** | |||
|
|||
- For each input Value {value} in the document: | |||
- For each literal Input Value {value} in the document: |
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.
Suggestion to makes the locations explicit:
- For each literal Input Value {value} in the document: | |
- For each argument Value and variable DefaultValue {value} in the document: |
I think this covers it all?
It makes it easier for implementers to make sure they cover everything and removes ambiguity about list/object literals (they are a Value
that may contain nested Value
, we only need to validate the root value)
The algorithm could rule out variables as the first step:
- If {value} is not a variable
- ...
- {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). |
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.
What about custom scalars? Should they also be skipped as their coercing is implementation dependant?
It's not an issue for a server but GraphiQL for an example cannot really enforce this without knowledge about the implementation that is not available in introspection.
An Input Value is defined as being either a variable (if not const) or one of the literal types (IntValue, FloatValue, StringValue, BooleanValue, NullValue, EnumValue, ListValue or ObjectValue).
The rule "Values of Correct Type" states:
However, an input value can be a variable, and variable coercion is handled at runtime (by CoerceVariableValues). Further, we already have a rule that validates that variables are only used in the positions in which they are allowed: All Variable Usages Are Allowed.
It seems to me that "Values of Correct Type" only meant to handle literal input values, so I've added the word "literal" for clarity. I've also expanded the explanation to reference where to look for variable input value validation. Since input coercion for Input Object references "runtime value", and validation doesn't have access to runtime values, I've made explicit the assumption that values represented by variables will be of the requisite type.
This is an alternative solution to, and
Thank you to @yaacovCR for pointing out this deficiency 🙌