我正在尝试在某些字段上设置静态cacheControl,如此处所示
根据我的理解,我需要使用指令,因此我使用以下嵌套文档来声明指令
因此,我构建了一个 cacheControl 指令,这就是我的 GraphQLModule.forRootAsync 在 buildSchemaOptions 中的内容:
buildSchemaOptions: {
directives: [
new GraphQLDirective({
name: 'cacheControl',
locations: [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.UNION
],
args: {
maxAge: { type: GraphQLInt },
scope: {
type: new GraphQLEnumType({
name: 'CacheControlScope',
values: {
PUBLIC: {
astNode: {
kind: 'EnumValueDefinition',
description: undefined,
name: {
kind: 'Name',
value: 'PUBLIC'
},
directives: []
}
},
PRIVATE: {
astNode: {
kind: 'EnumValueDefinition',
description: undefined,
name: {
kind: 'Name',
value: 'PRIVATE'
},
directives: []
} …
Run Code Online (Sandbox Code Playgroud)