Skip to content

GraphQL select: true Breaks Block Fields #15460

@jhb-dev

Description

@jhb-dev

Describe the Bug

When using select: true in Payload CMS GraphQL queries while using MongoDB, block fields return null and cause a 500 error. This affects ALL blocks, regardless of their content.

Error:

Cannot return null for non-nullable field Content.text.
Without select: true With select: true
Image Image

Link to the code that reproduces this issue

https://github.com/jhb-dev/payload-graphql-select-blocks-issue

Reproduction Steps

  1. Clone the reproduction repository and run the development server with pnpm dev
  2. Create test data:
    curl -X POST http://localhost:3000/api/examples -H "Content-Type: application/json" \
      -d '{"name":"Test","content":[{"blockType":"content","text":"Hello World"}]}'
  3. Open GraphQL Playground at http://localhost:3000/api/graphql-playground
  4. Run these queries:

Query WITHOUT select: true (works)

query ExamplesWithoutSelect {
  Examples {
    docs {
      name
      content {
        ... on Content {
          text
        }
      }
    }
  }
}

Result: {"data":{"Examples":{"docs":[{"name":"Test","content":[{"text":"Hello World"}]}]}}}

Query WITH select: true (fails)

query ExamplesWithSelect {
  Examples(select: true) {
    docs {
      name
      content {
        ... on Content {
          text
        }
      }
    }
  }
}

Result: 500 error, content: null

{
  "errors": [{"message": "Something went wrong.", "path": ["Examples","docs",0,"content",0,"text"]}],
  "data": {"Examples": {"docs": [{"name": "Test", "content": null}]}}
}

Which area(s) are affected?

area: graphql

Environment Info

payload: 3.74.0
@payloadcms/graphql: 3.74.0
next: 15.4.11

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions