Skip to content

Strange AppSync errors (Amplify Gen 1)

0

I have an old Gen 1 Amplify app that has, as of today, started returning errors that it previously didn't.

My schema defines a nullable field of another type.

When a query is made that requests this field, the data returned has "null" but the errors state that the non-nullable fields of the null type are required:

{
    "data": {
        "createPost": {
            "id": "7bc9f0d3-7d9b-49c2-b098-1f46910222dc",
            "slug": "test-0f9T4MRlS-",
            "type": "post",
            "title": "Test",
            "shortDesc": "<p>Test</p>",
            "author": "",
            "published": true,
            "version": 1,
            "content": "<p>Test</p>",
            "image": "",
            "storageImage": null,
            "tags": {
                "items": [],
                "nextToken": null,
                "__typename": "ModelPostTagsConnection"
            },
            "ups": null,
            "downs": null,
            "lockedBy": null,
            "createdAt": "2025-09-15T16:18:57.532Z",
            "osIndex": "posts",
            "osIdField": "id",
            "publishedAt": null,
            "updatedAt": "2025-09-15T16:18:57.532Z",
            "postStorageImageBucket": null,
            "postStorageImageKey": null,
            "__typename": "Post"
        }
    },
    "errors": [
        {
            "path": [
                "createPost",
                "storageImage",
                "bucket"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'String' within parent 'Storage' (/createPost/storageImage/bucket)"
        },
        {
            "path": [
                "createPost",
                "storageImage",
                "key"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'String' within parent 'Storage' (/createPost/storageImage/key)"
        },
        {
            "path": [
                "createPost",
                "storageImage",
                "contentType"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'String' within parent 'Storage' (/createPost/storageImage/contentType)"
        },
        {
            "path": [
                "createPost",
                "storageImage",
                "lastModified"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'String' within parent 'Storage' (/createPost/storageImage/lastModified)"
        },
        {
            "path": [
                "createPost",
                "storageImage",
                "createdAt"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Storage' (/createPost/storageImage/createdAt)"
        },
        {
            "path": [
                "createPost",
                "storageImage",
                "updatedAt"
            ],
            "locations": null,
            "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Storage' (/createPost/storageImage/updatedAt)"
        }
    ]
}

Has anything changed with AppSync in the last few days?

Thanks, Richard

5 Answers
0

The errors you're seeing are related to how AWS AppSync handles null values for fields that have non-nullable nested fields. When AWS AppSync is unable to process a request properly due to invalid data or syntax, it will return the field data with values set to null along with relevant errors.

In your case, the storageImage field itself is nullable in your schema, but the fields within the Storage type (bucket, key, contentType, lastModified, createdAt, updatedAt) are defined as non-nullable (required). When the parent field storageImage is null, AppSync is still trying to resolve its child fields, which are non-nullable, resulting in these errors.

This behavior might have been more lenient before, but it appears that AppSync is now more strictly enforcing the schema validation rules. This could be due to a recent update or change in how AppSync processes GraphQL responses.

To resolve this issue, you have a few options:

  1. Make the fields within your Storage type nullable in your schema
  2. Ensure that when storageImage is provided, all required fields within it are populated
  3. Update your resolver to handle this case more gracefully

This type of error is common in GraphQL when dealing with nested objects that have required fields but the parent object is nullable.
Sources
Troubleshooting and common mistakes in AWS AppSync - AWS AppSync
ErrorDetail - AWS AppSync

answered a year ago

0

In response to the AI answer...

The AppSync API is managed via Amplify so I can't go off piste and start modifying resolvers. I don't think making all fields nullable is an option and making sure all fields are populated wouldn't work as how does the caller know there will be an image available?

Remember that this is all done via Amplify Gen 1 with auto generated code. Why would AppSync try to resolve nested required fields if the parent is null?

answered a year ago

0

✅ Problem:

Nullable parent type, but non-nullable children → AppSync now throws “Cannot return null for non-nullable type.”

💡 Cause:

AWS likely rolled out stricter schema validation in AppSync recently (enforcing GraphQL spec compliance).

💡 Fix:

Update schema: make child fields nullable if parent can be null. Example:

type Storage { bucket: String key: String contentType: String lastModified: String createdAt: AWSDateTime updatedAt: AWSDateTime }

Or use a resolver override to return an empty object with empty strings instead of null.

answered a year ago

0

Thanks for the reply.

I can't make the child fields nullable as the primary key cannot be null.

The GraphQL spec says that if the parent is null then all sub items won't be resolved.

The current behavior doesn't seem right.

answered a year ago

0

Hey Richard, AWS team,

we're experiencing the exact same issue with an Amplify Gen 1 / AppSync API. Mutations that include a nullable @belongsTo relationship (in our case, User.restaurant: Restaurant @belongsTo) are returning errors like: "Cannot return null for non-nullable type: 'ID' within parent 'Restaurant' (/updateUser/restaurant/id)" The restaurant field on User is nullable, but when it resolves to null, AppSync still attempts to resolve the nested id: ID! field on Restaurant, which then fails.

Key observations:

  • Nothing changed on our side (schema, resolvers, or code)
  • This started happening recently
  • The GraphQL spec clearly states that if a parent field resolves to null, child fields should NOT be resolved
  • This appears to be a stricter AppSync validation that breaks existing Amplify Gen 1 apps

Temporary mitigations we've explored that did not resolve the issue:

  • Ensuring the foreign key (restaurantUsersId) is always populated when saving
  • Removing the relationship field from selection sets when not needed
  • Considering a separate nullable wrapper type

Has anyone found a proper fix or heard from AWS about this change? This seems like a breaking change for existing Amplify Gen 1 applications that relied on nullable relationships working correctly.

answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.