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 2 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 variable's 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 7d86799
🔍 Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/6710e1ecad32aa00079df192
😎 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.

- Let {type} be the type expected in the position {value} is found.
- {value} must be coercible to {type}.
- {value} must be coercible to {type} (with the assumption that any
{variableUsage} nested within {value} will represent a runtime value of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two conditions mentioned below, that the variable usage is allowed and that the variable value will coerce at runtime, but only one assumption is mentioned here. Is that intentional?

Suggested change
{variableUsage} nested within {value} will represent a runtime value of the
{variableUsage} nested within {value} is allowed and will represent a runtime value of the

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is deliberate: coercion happens at runtime where variables are already resolved; for us to run coercion during validation we need to run a slightly modified coercion - the modification being that it assumes (singular assumption) each variable reference it sees (something coercion would not normally understand) is equivalent to an arbitrary runtime value of that variable's type. It does not need to assume that the variable is allowed, from its point of view the variable exists whether it's allowed or not.

The foundation of that singular assumption is the behaviour of "All Variable Usages Are Allowed" combined with "Coercing Variable Values" - these aren't assumptions, these are specified behaviours.

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.

2 participants