Skip to content

Validation of variable values #3169

@dkbarn

Description

@dkbarn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions