aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

Incorrect handling of GraphQL variables when no value is supplied

Open sbaird32 opened this issue 5 months ago • 2 comments

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

sbaird32 avatar Feb 05 '24 22:02 sbaird32

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

onlybakam avatar Feb 07 '24 22:02 onlybakam

In JavaScript resolvers.

sbaird32 avatar Feb 07 '24 22:02 sbaird32