aws / aws/aws-appsync-community
Error message references the wrong type when an input type is invalid.
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
## Description
When a field in an input type is missing the reported error message is wrong.
There is an input type with a nested type:
```graphql
type Mutation {
createItem(outside_input: OutsideInput!): String
}
input OutsideInput {
nested: NestedInput
}
input NestedInput {
name: String!
}
```
When the `name` is missing from the variables (note that it's marked as required, so it's an input error):
```json
{"outside_input": {"nested": {}}}
```
The error message incorrectly points to the outer type:
```
Variable 'outside_input' has coerced Null value for NonNull type 'String!'
```
Note that the `outside_input` is:
* not `Null`
* not `String!`
Instead, the `NestedInput.name` is `Null` that is expected to be `String!`.
## Reproduction
Deploy this stack:
```yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
AppSyncAPI:
Type: AWS::AppSync::GraphQLApi
Properties:
Name: InputValidationTestAPI
AuthenticationType: API_KEY
GraphQLSchema:
Type: AWS::AppSync::GraphQLSchema
Properties:
ApiId: !GetAtt AppSyncAPI.ApiId
Definition: |
type Mutation {
createItem(outside_input: OutsideInput!): String
}
input OutsideInput {
nested: NestedInput
}
input NestedInput {
name: String!
}
type Query {
dummy: String
}
schema {
query: Query
mutation: Mutation
}
APIKey:
Type: AWS::AppSync::ApiKey
Properties:
ApiId: !GetAtt AppSyncAPI.ApiId
```
Send this query:
```graphql
mutation MyMutation($outside_input: OutsideInput = {}) {
createItem(outside_input: $outside_input)
}
```
With these variables:
```json
{"outside_input": {"nested": {}}}
```
Observe the result:
```json
{
"data": null,
"errors": [
{
"path": null,
"locations": [
{
"line": 1,
"column": 21,
"sourceName": null
}
],
"message": "Variable 'outside_input' has coerced Null value for NonNull type 'String!'"
}
]
}
```
Contributor guide
Research direction
Start by deploying the provided AWS AppSync CloudFormation stack and running the mutation with the supplied variables. Trace how nested GraphQL input coercion constructs the validation error; done means the message identifies NestedInput.name as null for the expected String! type instead of referring to outside_input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100