FormingPromptclaude-codecodexpublished fresh until

GraphQL: where should authorization checks live?

Summary When moving GraphQL authorization from parent checks to the business layer, centralize policy and test every protected resolver path before migration; the example delegates through ctx.posts.readBody({ actor: ctx.user, post }).

Not for GraphQL unknown-field or argument validation errors; see graphql-cannot-query-field-unknown-argument-schema-validation.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
APrompt · v1.0.0GraphQL authorization migration brief
How you use itYou paste it when you need it
What it can dowrites files; Shell and network instructions not verified; read the prompt text before running it.
What's inside
APrompt · v1.0.0GraphQL authorization migration brief
How you use it
You paste it when you need it
What it can do
writes files; Shell and network instructions not verified; read the prompt text before running it.
What's inside

What this thread does

Keep authorization policy in the business layer, call it from every path to protected data, and lock down response behavior with tests before moving checks across fields.

Do first: Add an unauthorized nested-field case to your resolver integration test file, asserting the existing data and error shape.

Migrate without opening a second path

1. Have the agent map every way to reach the protected data: direct lookup, lists, relationships, global node lookup if present, mutation return values and alternate interfaces. Authentication identifies the caller; it does not authorize access to every field. 2. Define the decision in one service/policy function with explicit actor, resource, tenant and action inputs. A resolver delegates to it rather than repeating role comparisons. 3. Record existing denial semantics. Choose whether the protected field returns null or raises an authorization error; test the exact response shape and error path. Non-null fields can propagate a failure to a nullable ancestor. 4. Add subfield checks before removing the parent check. A parent-only check can be bypassed through another route to the same object; a field-only check cannot protect an already returned sensitive sibling. 5. Review returned objects and default field resolution. Never let a sensitive property ride along in an object that an unguarded default resolver can expose. Return sanitized views or install explicit protected field resolvers. 6. Scope loaders/caches to the request or explicitly include all relevant authorization context. Recheck policy where required; a cached object is not evidence of permission. 7. Remove the redundant parent decision only after every sensitive path is covered and tests prove the intended partial response. Keep any parent-level policy that still protects object existence, tenant membership or list visibility.

Illustrative policy shape

// Application-owned pseudocode: adapt to your server and denial contract.
Post: {
  body(post, _args, ctx) {
    return ctx.posts.readBody({ actor: ctx.user, post });
  }
}

The service decides permission before returning the body. This adapter sketch is not a drop-in implementation; it omits transport, persistence and error mapping.

Tests to request before and after the move

CaseAssertion
Anonymous callerNo protected value; expected null/error contract
Owner with required permissionProtected field succeeds through all supported paths
Different user in the same tenantDenial if policy requires ownership
Same role in another tenantNo object or field leakage across tenant boundary
Nested relationship and direct lookupIdentical policy outcome
Alias or fragment selecting protected fieldSame authorization outcome as a plain selection
Public and protected siblingsIntended partial data, error path and null propagation
List with mixed ownershipDocumented filtering/denial behavior; no private list metadata
Mutation result containing protected objectSame checks as read paths
Successive callers using loadersOne caller's authorized result never leaks to another

Use the actual schema executor in integration tests, not only direct calls to policy helpers. Assert data and errors, and assert forbidden values never appear. Test policy revocation as well as initial permission. These are proposed tests, not reported passes.

Prompt for the agent

Inventory every path to the protected fields and show the existing denial contract. Write failing integration tests for unauthorized direct and nested access, alternate field selections and cross-tenant callers. Centralize the policy, add protected subfield adapters, then show passing tests before removing any old guard. Preserve unrelated response behavior and identify intentional contract changes.

Evidence — checked 2026-10-28

The GraphQL Foundation authorization guide recommends delegation to business logic; its execution guide explains resolver execution and its response guide describes partial data and field errors. Apollo's authorization documentation also distinguishes context creation and resolver/model checks.

GitLab's authorization guide describes an implementation where skipping a type check cascades to descendant fields. That is useful production implementation evidence for auditing inherited behavior, not a portable flag to copy into another server. Evidence: none found for a public trial of this exact migration plan.

Mistakes and limits

An @auth annotation is not enforcement until the server implements it. Denying only at the root is insufficient when the graph exposes alternate routes. Moving a guard can deliberately change partial data or reveal object existence; agree on that contract before optimizing repeated checks. No resolver suite, benchmark, framework-specific migration or cache-isolation test was run. GraphQL server implementations differ; this is a policy and test workflow, not a version-specific framework recipe.

Started from a post by @GraphQL Foundation, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# GraphQL: where should authorization checks live?
Summary: When moving GraphQL authorization from parent checks to the business layer, centralize policy and test every protected resolver path before migration; the example delegates through `ctx.posts.readBody({ actor: ctx.user, post })`.

## Options
- A · GraphQL authorization migration brief · early, no verdict yet · writes files; Shell and network instructions not verified; read the prompt text before running it.
Copy for agent
get the whatworks thread graphql-authz-subfield-migration-tests and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread graphql-authz-subfield-migration-tests

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · GraphQL authorization migration brief

An authored CC0-1.0 prompt template and evaluation checklist derived from this thread. Installation writes one Markdown file. No workflow trial or generated-output quality is claimed; checks verify file integrity.

Format
Prompt
Source
—
Pinned
v1.0.0 · sha256:50db0
Content hash
50db08e000737da2
Audit
scan passed
Can do
writes files; Shell and network instructions not verified; read the prompt text before running it.
Works with
claude-code · codex
Check
Authored prompt file exists in the project.; Verifies exact template/checklist bytes and final newline; does not prove workflow or generated-output quality.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-graphql-authz-migration-brief before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp