Description
Issue
Currently we retrieve directives by calling .directives
on the AST node, but this limits users with a code-first approach since in order for users to specify inheritMaxAge
it has to be statically defined
Context
apollo-server/packages/apollo-server-core/src/plugin/cacheControl/index.ts
Lines 305 to 321 in f6c5c9f
apollo-server/packages/apollo-server-core/src/plugin/cacheControl/index.ts
Lines 305 to 321 in f6c5c9f
apollo-server/packages/apollo-server-core/src/plugin/cacheControl/index.ts
Lines 323 to 333 in f6c5c9f
Proposal
We currently already use parts of @graphql-tools/*
. We can use @graphql-tools/utils
getDirectives
so that users with a code-first approach are able to specify directives via extensions.directives
.
So something like:
cacheAnnotationFromDirectives([
// read directives from schema
...t.astNode.directives,
// read directives specified under `extensions`
...getDirectives(schema, t.astNode)
])
and then users could do:
new GraphQLObjectType({
name: 'ObjectInheritingMaxAge',
fields: {
date: { type: new GraphQLNonNull(GraphQLDate) },
},
extensions: {
directives: {
cacheControl: {
inheritMaxAge: true,
},
},
},
})