How to integrate graphql-modules? #1429
-
Currently, we are using const schema = applyDirectives(application.schema);
const executor = application.createApolloExecutor();
const server = new ApolloServer({ schema, executor });
server.listen(3000); In order to migrate to envelop, we have to rewrite an executor: const applicationSchema = applyDirectives(application.schema);
const getEnveloped = envelop({
plugins: [useSchema(applicationSchema), useTiming()],
});
const server = new ApolloServer({
schema: applicationSchema,
executor: async requestContext => {
const { schema, execute, contextFactory } = getEnveloped({ req: requestContext.request.http });
return execute({
schema,
document: requestContext.document,
contextValue: await contextFactory(),
variableValues: requestContext.request.variables,
operationName: requestContext.operationName,
});
},
});
server.listen(3000); But in this case, we are loosing the Also, I've found an
Am I missing something? [update] I've found a solution, but it is still doesn't look perfect to me: const applicationSchema = applyDirectives(application.schema);
const getEnveloped = envelop({
- plugins: [useSchema(applicationSchema), useTiming()],
+ plugins: [useGraphQLModules(application), useTiming()],
});
const server = new ApolloServer({
schema: applicationSchema,
executor: async requestContext => {
- const { schema, execute, contextFactory } = getEnveloped({ req: requestContext.request.http });
+ const { execute, contextFactory } = getEnveloped({ req: requestContext.request.http });
return execute({
- schema,
+ schema: applicationSchema,
document: requestContext.document,
contextValue: await contextFactory(),
variableValues: requestContext.request.variables,
operationName: requestContext.operationName,
});
},
});
server.listen(3000); But in this case, we don't use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi there! Basically, with GraphQL-Modules you need to manage the lifecycle of the context and session, and this plugin does that for you. Regarding your solution, it seems fine for me, but I wonder why not using |
Beta Was this translation helpful? Give feedback.
Hi there!
We have a plugin for that! You can find it here: https://www.envelop.dev/plugins/use-graphql-modules
Basically, with GraphQL-Modules you need to manage the lifecycle of the context and session, and this plugin does that for you.
Regarding your solution, it seems fine for me, but I wonder why not using
const { execute, contextFactory, schema } = getEnveloped({ req: requestContext.request.http });
?The graphql-modules plugin should set the
schema
internally, and make it available throughgetEnveloped