question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation of variable values

See original GitHub issue

I’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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
glassercommented, Aug 2, 2021

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 getVariableValues stage out of execute so 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.)

0reactions
yaacovCRcommented, Oct 10, 2021

Update: #3302 supersedes #3193.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found