Registry /
devops / nestjs-gql-cache-control
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;
}
}
Errors
Common errors & fixes
Cannot find module 'nestjs-gql-cache-control'
Package not installed or ESM misconfiguration in CommonJS project.
fixnpm 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.
fixSwitch 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.
fixUse 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.
fixUse the CacheControlOptions type: import type { CacheControlOptions } from 'nestjs-gql-cache-control' 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