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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1303,14 +1303,23 @@ fragment resourceFragment on Resource {

**Formal Specification**

- For each input Value {value} in the document:
- 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}.
- {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.

referenced variable's type).

**Explanatory Text**

Literal values must be compatible with the type expected in the position they
are found as per the coercion rules defined in the Type System chapter.
are found as per the coercion rules defined in the Type System chapter. Variable
values are handled by the rule
[All Variable Usages Are Allowed](#sec-All-Variable-Usages-Are-Allowed).
{ListValue} and {ObjectValue} may nest additional Input Values, some of which
may be a {variableUsage}. Each nested {variableUsage} will be coerced during
execution - see [Coercing Variable Values](#sec-Coercing-Variable-Values) - thus
we assume their runtime value will coerce to the type of the referenced
variable.

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
Expand Down
Loading