Skip to content

fix(graphql): default global update data and use entity for policy type name (#19067) - #19077

Open
ghazy2001 wants to merge 1 commit into
payloadcms:mainfrom
ghazy2001:fix/graphql-globals-update-missing-data
Open

ghazy2001 wants to merge 1 commit into
payloadcms:mainfrom
ghazy2001:fix/graphql-globals-update-missing-data

Conversation

@ghazy2001

Copy link
Copy Markdown

Description

Fixes #19067.

Root Causes & Fixes

  1. resolvers/globals/update.ts:

    • When all fields on a global are hidden (or no data argument is supplied in the mutation), initGlobals.ts omits the data argument from update<Global>.
    • resolvers/globals/update.ts previously passed data: args.data, forwarding undefined to updateOperationGlobal which then threw a TypeError: Cannot read properties of undefined (reading '_status').
    • Updated line 42 to data: (args.data ?? {}) as any mirroring resolvers/collections/update.ts.
  2. schema/buildPoliciesType.ts:

    • buildPolicyType takes { type, entity, scope, typeSuffix }.
    • On line 220, globalTypeName was formatted using global?.graphQL?.name || slug. Because global was not a parameter in scope, Node's globalThis.global was referenced (returning undefined), unexpectedly falling back to slug instead of reading entity.graphQL?.name.
    • Updated line 220 to entity?.graphQL?.name || slug.

Verification

  • Added schema test in test/graphql/hidden-fields.int.spec.ts verifying that HiddenGlobalAccess and HiddenGlobalDocAccess use entity.graphQL.name rather than the slug fallback.
  • Formatted with oxfmt/prettier style (printWidth: 100, singleQuote: true, semi: false).

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between aebbf75 and b34ee8e.

Files selected for processing: 3
  • packages/graphql/src/resolvers/globals/update.ts
  • packages/graphql/src/schema/buildPoliciesType.ts
  • test/graphql/hidden-fields.int.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The global update resolver now defaults nullish data to an empty object. Global policy type names now use the entity’s GraphQL name when available, and a test checks the schema type names.

Changes: Hidden-global GraphQL behavior

Layer / File(s) Summary
Update handling and policy type naming
packages/graphql/src/resolvers/globals/update.ts, packages/graphql/src/schema/buildPoliciesType.ts, test/graphql/hidden-fields.int.spec.ts
The resolver passes {} when args.data is nullish. Global policy type names use entity.graphQL?.name or fall back to slug. The test checks that the HiddenGlobalAccess and HiddenGlobalDocAccess types exist and their snake-case alternatives do not.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • payloadcms/payload#19075: This PR makes the same resolver and policy type naming changes and adds regression coverage for hidden globals.
  • payloadcms/payload#18862: This PR changes hidden-field input generation and covers empty global updates, within the same hidden-global GraphQL behavior.

Suggested reviewers: paulpopus

Merge Risk: Minimal · up to b34ee

No actionable merge-blocking risk remains in the verified changes.

Security architecture risk: Low · up to b34ee

The changes are narrowly scoped and retain the existing update authorization checks and server-selected global identity. No authorization bypass was established. Applications may nevertheless observe renamed policy types or newly successful empty updates, including their configured hook effects.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Each update invocation remains scoped to the server-configured global captured by its resolver, subject to that application's access policy. The changed data expression gives the caller no new ability to select another global or request an access override.

Trust Boundaries and Controls

  • observed — The empty-object fallback still reaches globalConfig.access.update through executeAccess before document retrieval and persistence. A false access result throws Forbidden; when no callback is supplied, executeAccess requires an authenticated request user. Custom callbacks receive the normalized data, so their application-specific semantics remain relevant.

Resilience and Maintainability Implications

  • observed — The newly successful path retains transaction initialization, existing lock checks, commit after change hooks, and transaction cleanup on thrown errors. Empty updates are not guaranteed to be side-effect-free or idempotent: configured hooks and normal update processing still execute. The normalization introduces no new concurrency or external-side-effect rollback guarantee.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the two changes in the PR: defaulting global update data to an empty object, and using the entity name for the global policy type name. It also carries the conventional-commit prefix a…
Description check Passed The description states the root causes and the fixes for both files. It names the affected lines and the error that was thrown. It also describes the schema test added in hidden-fields.int.spec.ts, so…
Linked Issues check Passed Directly linked issue #19067 has two coding objectives. Both are implemented at the reviewed head.

1. Default missing global update data to {} [#19067]: packages/graphql/src/resolvers/globals/update.…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes three files. Each change maps to the linked issue #19067.

- packages/graphql/src/resolvers/globals/update.ts: one line, the data default. This imple…
Full details: Title check

Explanation

The title names the two changes in the PR: defaulting global update data to an empty object, and using the entity name for the global policy type name. It also carries the conventional-commit prefix and the issue number. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description states the root causes and the fixes for both files. It names the affected lines and the error that was thrown. It also describes the schema test added in hidden-fields.int.spec.ts, so it relates directly to the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #19067 has two coding objectives. Both are implemented at the reviewed head.

  1. Default missing global update data to {} [#19067]: packages/graphql/src/resolvers/globals/update.ts line 42 now reads data: (args.data ?? {}) as any. The base revision passed data: args.data. This matches the pattern the issue cites in resolvers/collections/update.ts. When the mutation omits data, updateOperationGlobal now receives {} instead of undefined.

  2. Derive the global policy type name from the entity [#19067]: packages/graphql/src/schema/buildPoliciesType.ts line 220 now reads formatName(${entity?.graphQL?.name || slug}${typeSuffix || ''}). The base revision read global?.graphQL?.name, where global resolved to Node's globalThis.global. The fallback to slug is kept.

An automated schema test was added in test/graphql/hidden-fields.int.spec.ts. It asserts that HiddenGlobalAccess and HiddenGlobalDocAccess exist and that hidden_globalAccess and hidden_globalDocAccess do not. formatName does not change letter case, so the buggy slug-based name would produce the lowercase names the test rejects. The test therefore distinguishes the fixed and buggy behavior, provided the hidden global config sets graphQL.name to HiddenGlobal. I did not verify that config setting. The issue does not require a test for the resolver change. No coding requirement is unmet.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes three files. Each change maps to the linked issue #19067.

  • packages/graphql/src/resolvers/globals/update.ts: one line, the data default. This implements objective 1.
  • packages/graphql/src/schema/buildPoliciesType.ts: one line, the globalTypeName source. This implements objective 2.
  • test/graphql/hidden-fields.int.spec.ts: one added test for the policy type names. It covers the buggy naming path from objective 2 and is supporting test coverage.

The PR does not modify initGlobals.ts, and no unrelated files change. The as any cast mirrors the existing collection resolver pattern. No change lacks a connection to the linked issue.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graphql: resolvers/globals/update does not default args.data to {} when all fields are hidden and buildPolicyType reads globalThis.global

1 participant