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

Validate that Value::Variable is not used in const locations #852

Closed
SimonSapin opened this issue Apr 9, 2024 · 0 comments · Fixed by #925
Closed

Validate that Value::Variable is not used in const locations #852

SimonSapin opened this issue Apr 9, 2024 · 0 comments · Fixed by #925
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation bug Something isn't working triage

Comments

@SimonSapin
Copy link
Contributor

In the GraphQL spec, the Value grammar has a Const parameter that disallows referencing a variable in type system locations, where variables don’t exist. As of apollo-compiler 1.0.0-beta.15, we have a single Value Rust enum with a Variable variant. Since #777 apollo-parser correctly emits parse errors when a variable is used in a const context. But since apollo-compiler data structures are mutable, it is still possible construct a wrong value programatically.

These is discussion of encoding constness in the type system but that may or may not be the best way forward. Until that happens (if it does), validation should emit a diagnostic if Value::Variable is use incorrectly. This is in the same spirit as having both #847 and #845.

@SimonSapin SimonSapin added bug Something isn't working triage apollo-compiler issues/PRs pertaining to semantic analysis & validation labels Apr 9, 2024
SimonSapin added a commit that referenced this issue Nov 4, 2024
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.
SimonSapin added a commit that referenced this issue Nov 4, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant