apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
566 stars 43 forks source link

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

Open SimonSapin opened 5 months ago

SimonSapin commented 5 months ago

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 https://github.com/apollographql/apollo-rs/pull/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 https://github.com/apollographql/apollo-rs/pull/847 and https://github.com/apollographql/apollo-rs/pull/845.