graphql-spec
graphql-spec copied to clipboard
Clarify allowed values for variables
The GraphQL spec doesn't mention the restrictions on variable types. For example:
query($value: SomeScalar) {
# ...
}
And in variables:
{ "value": { "foo-bar": 5 } }
Is this allowed? foo-bar is not a valid Name and so the data can't be represented inline, but scalars can represent any value. I don't think the GraphQL spec actually clarifies about this anywhere.
Yes this is permitted, it is supported by the reference implementation, and there are common scalars that use it such as the JSON scalar. Older versions of GraphiQL could not validate this in the variables tray, it would always appear invalid (though it would work fine when you execute the operation), I’m not sure if that’s been resolved.