Skip to content

Deleting a document used in relation inside array causes GraphQL error #9788

@suphon-t

Description

@suphon-t

Describe the Bug

I have a global A with an array that has a relation to collection B.
When a document in B is used in A, B can be deleted without any errors.
But after the deletion, fetching A via GraphQL will result in a server error because the related document is null, but the schema doesn't allow null.

Link to the code that reproduces this issue

https://github.com/suphon-t/payload/blob/reproduce/graphql-error-from-deleted-relation/test/_community/int.spec.ts

Reproduction Steps

In the schema I have a collection Posts and a global Home.
Home has an array topPosts consisting of a relation to a post, and a text field caption.

  1. Create a new post 'post 1'
  2. Edit the Home global and add an item in topPosts relating to 'post 1'
  3. Delete 'post 1'
  4. Get the Home global through GraphQL
  5. The server throws a schema error
    Image

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 4.0.2
  pnpm: 9.14.4
Relevant Packages:
  payload: 3.4.0
  next: 15.0.3
  @payloadcms/db-postgres: 3.4.0
  @payloadcms/email-nodemailer: 3.4.0
  @payloadcms/graphql: 3.4.0
  @payloadcms/next/utilities: 3.4.0
  @payloadcms/payload-cloud: 3.4.0
  @payloadcms/plugin-cloud-storage: 3.4.0
  @payloadcms/plugin-seo: 3.4.0
  @payloadcms/richtext-lexical: 3.4.0
  @payloadcms/storage-s3: 3.4.0
  @payloadcms/translations: 3.4.0
  @payloadcms/ui/shared: 3.4.0
  react: 19.0.0-rc-66855b96-20241106
  react-dom: 19.0.0-rc-66855b96-20241106
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Sun Nov  3 20:57:51 PST 2024; root:xnu-11215.60.405~54/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions