Skip to content

GraphQL API select flag returns relationship fields as empty arrays #14467

@jhb-dev

Description

@jhb-dev

Describe the Bug

The GraphQL API select flag introduced in PR #13711, returns relationship fields as empty arrays.

Relationship fields are correctly returned with select: false, but not with select: true:

select: true result select: false result
Image Image
authors and relatedDocuments are returned as [] authors and relatedDocuments are correctly returned

The issue occurs for both polymorphic and non-polymorphic relationship fields. Join fields seem to work, though.

Link to the code that reproduces this issue

https://github.com/jhb-dev/payload-gql-select-reproduction

Reproduction Steps

  1. run the reproduction app
  2. create a new user and set
  3. create a new blogpost (add an author and related document)
  4. update the users favorite blogpost field to point to the blogpost
  5. open the GraphQL Playground at /api/graphql-playground
  6. paste the query you can find below and toggle the select field to see the difference
GraphQL query for the GraphQL Playground
query BlogPostBySlug($title: String!) {
  Blogposts(where: { title: { equals: $title } }, select: true) {
    docs {
      id
      title
      subTitle
      authors {
        id
        email
      }
      relatedDocuments {
        relationTo
        value {
          ... on User {
            id
            email
          }

          ... on Media {
            id
          }
        }
      }
      likedBy {
        docs {
          id
          email
        }
      }
    }
  }
}

Query Variables:

{
  "title": "test"
}

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

area: core

Environment Info

Binaries:
  Node: 24.3.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.12.4
Relevant Packages:
  payload: 3.62.1
  next: 15.4.4
  @payloadcms/db-mongodb: 3.62.1
  @payloadcms/email-nodemailer: 3.62.1
  @payloadcms/graphql: 3.62.1
  @payloadcms/next/utilities: 3.62.1
  @payloadcms/payload-cloud: 3.62.1
  @payloadcms/richtext-lexical: 3.62.1
  @payloadcms/translations: 3.62.1
  @payloadcms/ui/shared: 3.62.1
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions