Is it possible to use defer with ApolloGateway?
I have this config on my ApolloGateway:
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: SubgraphContainer.list().map(({name, url}) => ({ name, url })),
}),
buildService: ({ name }) => {
const subgraph = SubgraphContainer.get(name)
const datasource = buildGraphQLDataSource(subgraph);
return datasource;
},
__exposeQueryPlanExperimental: true,
queryPlannerConfig: {
incrementalDelivery: {
enableDefer: true,
}
},
})
But @defer does not works
Error: Unknown directive "@defer".
I have installed graphql 17 using:
npm i --legacy-peer-dep graphql@17.0.0-alpha.2
In another project without Apollo Gateway, I just needed to add this snippet (including graphql 17) to work:
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
const transformedSchema = new GraphQLSchema({
...schema.toConfig(),
directives: [...schema.getDirectives(), ...specifiedDirectives, GraphQLDeferDirective]
})
const server = new ApolloServer<Context>({
schema: transformedSchema
})
I have some directives and I apply them like this:
const directiveTransformers = [
//...
];
const transformedSchema = directiveTransformers.reduce((schema, transformer) =>
transformer(schema), buildSubgraphSchema({
typeDefs,
resolvers,
})
)
I can’t add GraphQLDeferDirective from the ‘graphql’ package to my directiveTransformers array, because GraphQLDeferDirective is of type GraphQLDirective, and my transformers (created using mapSchema from ‘@graphql-tools/utils’) return GraphQLSchema