Skip to content

index.TypeAlias.CacheKey

github-actions[bot] edited this page Nov 30, 2026 · 13 revisions

Type Alias: CacheKey

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.

Parameters

parent

unknown

args

unknown

context

any

info

GraphQLResolveInfo

Returns

unknown

Remarks

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.

Example

const inOrg = rule(
  async (parent: { orgId: string }, _args, ctx) => ctx.orgs.has(parent.orgId),
  { name: 'inOrg', cache: (parent: { orgId: string }) => parent.orgId },
);

API Reference

Clone this wiki locally