Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of GraphQL variables when no value is supplied #348

Open
sbaird32 opened this issue Feb 5, 2024 · 2 comments
Open

Incorrect handling of GraphQL variables when no value is supplied #348

sbaird32 opened this issue Feb 5, 2024 · 2 comments

Comments

@sbaird32
Copy link

sbaird32 commented Feb 5, 2024

If a variable is used for a nullable query argument, the resolver function will see an explicit null even if no value was provided for the variable.

For example, given this schema snippet:

type Item {
   name: String!
}

type Query {
   items(after: String): [Item!]
}

and this query:

query MyQuery($after: String) {
   items(after: $after) {
      name
   }
}

and no variable values provided:

Operation: MyQuery, Variables: {}

...the expected behavior is that after is absent from the context.arguments object passed to the resolver function, but instead after is present with an explicit null value:

{
   "after": null
}

This makes it impossible to differentiate between absent and null when the client is using variables.

Here is the relevant section of the GraphQL spec: https://spec.graphql.org/October2021/#sec-Coercing-Variable-Values

@onlybakam
Copy link
Contributor

Hey @sbaird32 , thanks for reaching out. are you seeing this behavior in JavaScript resolvers or in a VTL template?

@sbaird32
Copy link
Author

sbaird32 commented Feb 7, 2024

In JavaScript resolvers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants