Skip to content

GraphQL runs into InvariantViolation when user deletes an asset used in a required field #11974

@lostgeek

Description

@lostgeek

Bug description

Our user deleted an asset that was used in a required field on a page. When fetching that entry via the GraphQL API, we got an error:

production.ERROR: Cannot return null for non-nullable field "Entry_Pages_ContentPage.cover_image". {"exception":"[object] (GraphQL\\Error\\InvariantViolation(code: 0): Cannot return null for non-nullable field \"Entry_Pages_ContentPage.cover_image\".

This happens as the entry now contains null, while its GraphQL type is marked as non-nullable.

How to reproduce

  1. Create a blueprint with a required asset field.
  2. Create an entry with an asset.
  3. Delete the asset via the asset browser.
  4. Fetch the entry via GraphQL.

Logs

Environment

Environment
Application Name: <redacted>
Laravel Version: 11.45.1
PHP Version: 8.3.23
Composer Version: 2.8.9
Environment: local
Debug Mode: ENABLED
URL:  <redacted>
Maintenance Mode: OFF
Timezone: UTC
Locale: de

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: sqlite
Logs: stack / daily
Mail: smtp
Queue: redis
Session: redis

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 4.15.1
PHP SDK Version: 4.14.1
Release: 9ea1348
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: 1%
Sample Rate Profiling: 1%
Send Default PII: ENABLED

Statamic
Addons: 4
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.58.1 PRO

Statamic Addons
cnj/seotamic: 5.0.2

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions