aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

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

Open sbaird32 opened 9 months ago

sbaird32 commented 9 months ago

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 commented 9 months ago

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

sbaird32 commented 9 months ago

In JavaScript resolvers.