Registry / devops / nestjs-gql-cache-control

nestjs-gql-cache-control

JSON →
library0.1.2jsnpmunverified

A lightweight decorator for setting cache control hints on GraphQL resolvers in NestJS applications. Version 0.1.2 targets Node.js >=10 and ships with TypeScript types. It integrates with Apollo Server's cache control and response cache plugins, allowing per-resolver configuration of maxAge and scope. Released on npm with no active updates since initial launch; relies on @nestjs/graphql, apollo-server-core, and apollo-server-plugin-response-cache as peer/optional dependencies.

npm install nestjs-gql-cache-control
INSTALL
IMPORT
SIG · NESTJS-GQL-CACHE-C
N
nestjs-gql-cache-control
devopsjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CacheControl
import { CacheControl } from 'nestjs-gql-cache-control'
const CacheControl = require('nestjs-gql-cache-control')
Package is ESM-only. Does not support CommonJS require.
CacheControlOptions
import type { CacheControlOptions } from 'nestjs-gql-cache-control'
import { CacheControlOptions } from 'nestjs-gql-cache-control'
CacheControlOptions is a TypeScript type alias for the options object. Use type-only import to avoid runtime error.
default
import CacheControl from 'nestjs-gql-cache-control'
import { default } from 'nestjs-gql-cache-control'
Default export is the decorator factory; named export also available.

Shows setup of GraphQL module with cache plugins and usage of @CacheControl decorator on query and field resolvers.

// app.module.ts import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import responseCachePlugin from 'apollo-server-plugin-response-cache'; import { ApolloServerPluginCacheControl } from 'apollo-server-core/dist/plugin/cacheControl'; import { PostResolver } from './post.resolver'; @Module({ imports: [ GraphQLModule.forRoot({ autoSchemaFile: 'schema.gql', plugins: [ ApolloServerPluginCacheControl({ defaultMaxAge: 5 }), responseCachePlugin(), ], }), ], providers: [PostResolver], }) export class AppModule {} // post.resolver.ts import { Resolver, Query, ResolveField } from '@nestjs/graphql'; import { CacheControl } from 'nestjs-gql-cache-control'; @Resolver('Post') export class PostResolver { @Query(() => [Post]) @CacheControl({ maxAge: 10 }) posts() { return [{ id: 1, title: 'Hello', owner: { id: 1, name: 'Alice' }, hasLiked: false }]; } @ResolveField(() => User) @CacheControl({ inheritMaxAge: true }) owner() { return { id: 1, name: 'Alice' }; } @ResolveField(() => Boolean) @CacheControl({ maxAge: 5, scope: 'PRIVATE' }) hasLiked() { return false; } }
Debug
Known issues
gotchaWithout setting inheritMaxAge on nested fields or connections, those fields default to maxAge 0 and cancel caching.
fix
Add @CacheControl({ inheritMaxAge: true }) on resolvers for fields that should inherit parent cache settings.
affects: >=0.1.0
deprecatedImporting ApolloServerPluginCacheControl from 'apollo-server-core/dist/plugin/cacheControl' is deprecated; prefer 'apollo-server-core' directly if version supports it.
fix
Use import { ApolloServerPluginCacheControl } from 'apollo-server-core' if using Apollo Server 3+.
affects: >=0.1.0
gotchaPackage uses ESM only; require() will throw a runtime error.
fix
Use import syntax or enable ESM in your project.
affects: >=0.1.0
gotchaThe decorator works only with @nestjs/graphql code-first approach; schema-first not supported.
fix
Ensure you use code-first (autoSchemaFile or schema generator).
affects: >=0.1.0
gotchaThe package is tightly coupled to apollo-server-plugin-response-cache; without it, cache control hints have no effect.
fix
Install and register apollo-server-plugin-response-cache in the plugins array.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'nestjs-gql-cache-control'
Package not installed or ESM misconfiguration in CommonJS project.
fix
npm install nestjs-gql-cache-control and ensure project uses ESM (type: module in package.json or .mjs extension).
TypeError: Class extends value undefined is not a constructor or null
Trying to use require() on an ESM-only package.
fix
Switch to import syntax: import { CacheControl } from 'nestjs-gql-cache-control'
CacheControl is not a function
Using named import but the decorator factory is default export.
fix
Use default import: import CacheControl from 'nestjs-gql-cache-control'
Property 'maxAge' does not exist on type 'CacheControlOptions'
TypeScript type mismatch: options object may have different shape.
fix
Use the CacheControlOptions type: import type { CacheControlOptions } from 'nestjs-gql-cache-control'
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
@nestjs/graphqlrequiredRequired to use the CacheControl decorator with NestJS resolvers
apollo-server-corerequiredRequired for ApolloServerPluginCacheControl plugin
apollo-server-plugin-response-cacherequiredRequired for full response caching functionality
Agent activity
2 hits · last 30 days
node
2
Resources
nestjs-gql-cache-control — npm install nestjs-gql-cache-control · libregistry