Skip to content

Make variables in const contexts validation errors #925

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

Merged
merged 1 commit into from
Nov 5, 2024
Merged

Conversation

SimonSapin
Copy link
Contributor

Fixes #852

GraphQL values can be of different kinds, including variables with the $x syntax. Variables are not allowed in some contexts, such as schemas. The parser already rejects them as syntax errors, but the Rust API allows mutating a document and representing variable values in contexts where they are not allowed.

It was already the case that would usually cause a validation error like variable `$x` is not defined. This PR ensures and tests that this is the case for every relevant context. It also makes related drive-by fixes:

  • Validate the default value of input fields and arguments
  • Validate the default value of variables once at their definition, not at every usage of the variable. This fixes duplicate diagnostics for a default value of incorrect type for a variable correctly used multiple times.

Fixes #852

GraphQL values can be of different kinds, including variables with the `$x` syntax.
Variables are not allowed in some contexts, such as schemas.
The parser already rejects them as syntax errors, but the Rust API allows mutating
a document and representing variable values in contexts where they are not allowed.

It was already the case that would usually cause a validation error like
``variable `$x` is not defined``. This PR ensures and tests that this is the case
for every relevant context. It also makes related drive-by fixes:

* Validate the default value of input fields and arguments
* Validate the default value of variables once at their definition,
  not at every usage of the variable. This fixes duplicate diagnostics
  for a default value of incorrect type for a variable correctly used multiple times.
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

great!

@SimonSapin SimonSapin merged commit 973254d into main Nov 5, 2024
12 checks passed
@SimonSapin SimonSapin deleted the const-values branch November 5, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate that Value::Variable is not used in const locations
2 participants