Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

benjie
Copy link
Member

@benjie benjie commented Oct 17, 2024

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:

  • For each input Value value in the document:
    • Let type be the type expected in the position value is found.
    • value must be coercible to type.

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 🙌

@benjie benjie added the ✏️ Editorial PR is non-normative or does not influence implementation label Oct 17, 2024
Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 0c25faa
🔍 Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/67cb1b5057e42c0008fe671e
😎 Deploy Preview https://deploy-preview-1118--graphql-spec-draft.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@benjie benjie force-pushed the values-of-correct-type-variables branch from df483ec to 7fe1b5a Compare October 17, 2024 09:38
@benjie benjie changed the title Clarify 'Values of Correct Type' rule does not apply to variables. Clarify 'Values of Correct Type' rule relates to literals Oct 17, 2024
@benjie
Copy link
Member Author

benjie commented Oct 17, 2024

@graphql/tsc I would love to get your input on this change.

Copy link
Contributor

@martinbonnin martinbonnin left a 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:
Copy link
Contributor

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:

Suggested change
- 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
    - ...

Comment on lines +1309 to +1311
- {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).
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Editorial PR is non-normative or does not influence implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants