- 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
The option
| Option | 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
| Case | Assertion |
|---|---|
| Anonymous caller | No protected value; expected null/error contract |
| Owner with required permission | Protected field succeeds through all supported paths |
| Different user in the same tenant | Denial if policy requires ownership |
| Same role in another tenant | No object or field leakage across tenant boundary |
| Nested relationship and direct lookup | Identical policy outcome |
| Alias or fragment selecting protected field | Same authorization outcome as a plain selection |
| Public and protected siblings | Intended partial data, error path and null propagation |
| List with mixed ownership | Documented filtering/denial behavior; no private list metadata |
| Mutation result containing protected object | Same checks as read paths |
| Successive callers using loaders | One 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
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.