Skip to content

fix(graphql): default args.data to {} in global update resolver and use entity.graphQL.name in buildPolicyType - #19075

Open
shafiktanbir wants to merge 1 commit into
payloadcms:mainfrom
shafiktanbir:fix/graphql-globals-update-and-policy-type
Open

shafiktanbir wants to merge 1 commit into
payloadcms:mainfrom
shafiktanbir:fix/graphql-globals-update-and-policy-type

Conversation

@shafiktanbir

Copy link
Copy Markdown

What?

  1. Defaults data to (args.data ?? {}) as any in packages/graphql/src/resolvers/globals/update.ts (matching packages/graphql/src/resolvers/collections/create.ts and update.ts).
  2. Uses entity?.graphQL?.name || slug instead of global?.graphQL?.name || slug in packages/graphql/src/schema/buildPoliciesType.ts (buildPolicyType).

Why?

  1. When a global mutation input type is omitted or args.data is not provided to the global update resolver, passing data: undefined to updateOperationGlobal throws MissingGlobalData. Collection create and update resolvers already default args.data ?? {}.
  2. In buildPolicyType, the parameter is destructured as entity (const { type, entity, scope, typeSuffix } = args). Referencing global?.graphQL?.name on line 220 read Node's ambient globalThis.global instead of the global config's graphQL.name, causing globalTypeName to always fall back to slug (e.g. hidden_globalAccess instead of HiddenGlobalAccess).

How?

  • Updated packages/graphql/src/resolvers/globals/update.ts line 42 to pass data: (args.data ?? {}) as any.
  • Updated packages/graphql/src/schema/buildPoliciesType.ts line 220 to compute globalTypeName from entity?.graphQL?.name || slug.
  • Added regression coverage in test/graphql/hidden-fields.int.spec.ts.

Fixes #19067

@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 298814b.

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; 9 remain after this review.

Walkthrough

The global update resolver now handles omitted data. Global access policy types now use the global entity’s configured GraphQL name or slug. A regression test covers both behaviors when global fields are hidden.

Changes: Global hidden-field GraphQL behavior

Layer / File(s) Summary
Global update 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 global update resolver passes an empty object when args.data is nullish. Global policy type names use the entity’s GraphQL name or slug, with the configured suffix. The regression test checks the type names and calls updateAllHiddenGlobal without arguments.

Priority: Low

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • payloadcms/payload#18862: It addresses hidden-field GraphQL mutation inputs and empty updates, including related collection resolver behavior and policy type changes.

Suggested reviewers: jarrodmflesch

Merge Risk: Minimal · up to 29881

The GraphQL global fixes are covered by focused regression tests and present no identified merge-blocking risk.

Security architecture risk: Low · up to 29881

The update still uses the existing permission and persistence path, and no new security bypass was identified. Clients that refer to the former access-policy type names may need to change when upgrading or rolling back.

Retained concerns

  • Low · architecture · inferred: For globals with a configured GraphQL name, clients that reference the former slug-derived access-policy type names will need to migrate; rolling back reverses those names again. This is a conditional public-schema compatibility risk, not an observed permission bypass.
Security review details

Security Blast Radius

  • inferred — The newly accepted nullish-data request can reach a global update, including its write and hooks, but only through the configured global’s existing mutation and update-operation path. No new service, credential, or authority path appears in the full PR diff.

Security Findings and Attack Paths

  • inferred — No PR-introduced authorization bypass was identified in the inspected empty-update path: normalization does not set overrideAccess, and the existing operation evaluates update access before retrieving or writing the global. This conclusion is limited to the inspected shared path.

Trust Boundaries and Controls

  • observed — The mutation takes caller-supplied arguments but obtains the request from GraphQL context. The resolver supplies neither overrideAccess nor showHiddenFields; the update operation evaluates global access and performs a final afterRead with those options unset.

Resilience and Maintainability Implications

  • inferred — Repeated empty updates can still invoke configured hooks and write timestamps; the PR does not change their implementation or the existing lock and transaction path. Adapter-specific concurrency guarantees and effects of application-specific hooks were not independently established.
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 args.data to {} in the global update resolver, and using entity.graphQL.name in buildPolicyType. It is specific and matches the changeset and link…
Description check Passed The description states both fixes with file paths and line references. It explains the cause: omitted args.data throws MissingGlobalData, and the global reference resolves to Node's globalThis.global.…
Linked Issues check Passed Issue #19067 requires two GraphQL fixes. packages/graphql/src/resolvers/globals/update.ts now passes (args.data ?? {}) as any to the global update operation. `packages/graphql/src/schema/buildPoli…
Out of Scope Changes check Passed The pull request changes only the global update resolver, global policy type-name construction, and regression coverage for these behaviors. These changes directly support issue #19067. No unrelated c…
Full details: Title check

Explanation

The title names the two changes in the PR: defaulting args.data to {} in the global update resolver, and using entity.graphQL.name in buildPolicyType. It is specific and matches the changeset and linked issue #19067. Its length is long, but it still conveys the main change.

Full details: Description check

Explanation

The description states both fixes with file paths and line references. It explains the cause: omitted args.data throws MissingGlobalData, and the global reference resolves to Node's globalThis.global. It also notes the added regression test and links issue #19067. It is related to the changeset.

Full details: Linked Issues check

Explanation

Issue #19067 requires two GraphQL fixes. packages/graphql/src/resolvers/globals/update.ts now passes (args.data ?? {}) as any to the global update operation. packages/graphql/src/schema/buildPoliciesType.ts now derives globalTypeName from entity?.graphQL?.name || slug. The added test verifies HiddenGlobalAccess and HiddenGlobalDocAccess and invokes the update resolver without arguments.

Full details: Out of Scope Changes check

Explanation

The pull request changes only the global update resolver, global policy type-name construction, and regression coverage for these behaviors. These changes directly support issue #19067. No unrelated change is shown in the whole-pull-request diff.

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