Repository navigation
index.TypeAlias.CacheKey
github-actions[bot] edited this page Nov 30, 2026
·
13 revisions
type CacheKey = (parent, args, context, info) => unknown;Defined in: packages/graphql-casl/src/rules.ts:256
A custom cache key for rule's cache option — the same escape hatch
graphql-shield offers when a function is passed as cache.
unknown
unknown
any
GraphQLResolveInfo
unknown
The check is evaluated once per request per distinct key. Keys compare with
Map semantics: primitives by value, objects by identity — so return a
string, a number, or the object whose identity you mean. Return undefined
to skip the cache for that call.
Use it when the built-in 'strict' key — parent identity plus the field's
arguments — is wrong in either direction: too coarse when the answer depends
on info.fieldName, too fine when rows from different parents share an
answer, e.g. a check that only cares about parent.orgId.
const inOrg = rule(
async (parent: { orgId: string }, _args, ctx) => ctx.orgs.has(parent.orgId),
{ name: 'inOrg', cache: (parent: { orgId: string }) => parent.orgId },
);