Skip to content

apollo.Function.reportDenialsPlugin

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

Function: reportDenialsPlugin()

function reportDenialsPlugin(): ReportDenialsApolloPlugin;

Defined in: packages/graphql-casl/src/apollo.ts:98

An Apollo Server plugin that reports the denials onDeny: 'filter' held for each request — the ones the response could not carry through the denied field itself — into the response before it is sent.

Returns

ReportDenialsApolloPlugin

The plugin, for Apollo Server's plugins array.

Remarks

It is reportDenials, called from willSendResponse with the request's contextValue; see ApplyPermissionsOptions.onDeny for which denials those are.

Under report: 'errors' they are appended to the response's errors, formatted the way Apollo formats its own; under report: 'extensions' they land in extensions.authorizationErrors. A request with nothing recorded leaves the response untouched, as does a request under 'reject' or 'mask', so the plugin is safe to install regardless of mode.

Only a kind: 'single' response is reported into. Under incremental delivery (@defer / @stream) the body is a stream the plugin does not follow, so a denial held for a deferred payload is silently masked — the same degradation as no hook at all.

Example

const server = new ApolloServer<Context>({
  schema: applyPermissions<Resolvers>(schema, permissions, { onDeny: 'filter' }),
  plugins: [reportDenialsPlugin()],
});

API Reference

Clone this wiki locally