Validation of variable values
See original GitHub issueI’m curious why it’s not possible to validate the values of variables using the validate framework.
For example, suppose I have a very simple validator that wants to assert the value for argument name contains only ascii characters, given this schema:
type Query {
hello(name: String!): String!
}
I can implement this validator and it will work when the incoming request is this:
{
'query': '{ hello(name: "foo") }'
}
but when the request is the following, I have no way of seeing the value for the VariableNode $myName from inside the validator:
{
'query': 'query myQuery($myName: String!) { hello(name: $myName) }',
'variables': {'myName': 'foo'}
}
It looks like it comes down to this bit of the code: https://github.com/graphql/graphql-js/blob/main/src/graphql.ts#L118-L122
Is there any reason why variableValues cannot also be passed in and made available to the validate framework?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Defining variable validation criteria - IBM
In the Variable Validation section, determine for which variables you want to set validation criteria, and select the data type for the value...
Read more >Terraform Variable Validation - Brendan Thompson
Before validation was introduced, it wasn't easy to check if the values passed into the Terraform configuration were valid or what we expected ......
Read more >Validating Variables - Pathagoras
"Validating a Variable" is geek for making sure that the data input is consistent with the request made and in the right format....
Read more >Custom Variable Validation in Terraform 0.13 - HashiCorp
We're excited to announce that custom variable validation is being released as a production-ready feature in Terraform 0.13.
Read more >Terraform variable validation - Medium
Why validate your variables? ... Although the syntax and configuration of your Terraform may be valid, the variables passed into your ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

My understanding is that the whole concept behind “validation” is that it is specifically a function of “operation + schema”. So for example, you can cache the result of parsing and validation and not run it multiple times for the same operation and schema if only variables are changing. (Apollo Server does this!)
That said, I would love to be able to separate the
getVariableValuesstage out ofexecuteso that we can report them with different kinds of error codes (and plugin callbacks!) in our request processing pipeline. @IvanGoncharov do you think that sort of change would be a reasonable PR? Would love to brainstorm exactly how to structure it. (We’d similarly want to pull out the “make sure an operation name is provided if needed and that it matches an operation in the document if provided” step.)Update: #3302 supersedes #3193.