Skip to content

fix(graphql): virtual fields should be nullable in GraphQL schema (#16112) - #16193

Merged
r1tsuu merged 5 commits into
payloadcms:mainfrom
deepshekhardas:fix/16112-virtual-field-graphql
Jul 9, 2026
Merged

r1tsuu merged 5 commits into
payloadcms:mainfrom
deepshekhardas:fix/16112-virtual-field-graphql

Conversation

@deepshekhardas

@deepshekhardas deepshekhardas commented Apr 7, 2026 •

Copy link
Copy Markdown

Rebased onto latest main.

@MurzNN MurzNN left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a bug with the defaultValue: if the field is marked as required and has the defaultValue, it is still marked as required in the GraphQL schema!

Proposed changes should fix this issue, I believe. @deepshekhardas, could you please check this?

const condition = field.admin && field.admin.condition
const isTimestamp = field.name === 'createdAt' || field.name === 'updatedAt'
// Virtual fields are computed by hooks, so they should be nullable in GraphQL inputs
const isVirtual = 'virtual' in field && field.virtual === true

@MurzNN MurzNN May 29, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isVirtual = 'virtual' in field && field.virtual === true
const isVirtual = 'virtual' in field && field.virtual === true
const hasDefaultValue = 'defaultValue' in field

!hasReadAccessControl &&
!isTimestamp
!isTimestamp &&
!isVirtual

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!isVirtual
!isVirtual &&
!hasDefaultValue

@r1tsuu
r1tsuu enabled auto-merge (squash) July 9, 2026 15:47
@r1tsuu
r1tsuu merged commit e055d81 into payloadcms:main Jul 9, 2026
267 of 277 checks passed
JarrodMFlesch added a commit that referenced this pull request Oct 27, 2026
#17256)

Port of #16193 to `3.x`

Co-authored-by: Deepshekhar Das <[email protected]>
Co-authored-by: deepshekhardas <[email protected]>
Co-authored-by: Jarrod Flesch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants