graphql-passport
graphql-passport copied to clipboard
Is this supported with express-graphql?
I see that your server is set up with Apollo Server. I am trying to configure this using express-graphql - with minimal luck.
Would you like to see my code or will it not work with express-graphql?
Sorry for the late reply. If you have an open-source repo it would make things easier for me to investigate. Not sure at this point how graphql-passport can work with express-graphql since it's been a while I worked with it :wink:
I'm also no expert in express-graphql but I think the key is in adding context using the the customExecuteFn:
const gqlServer = graphqlHTTP({
schema,
graphiql: true,
customExecuteFn: ({ contextValue: req, ...rest }: ExecutionArgs) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
execute({ ...rest, contextValue: buildContext({ req, res: {} }) }),
});
I created a test-branch for express-graphql here: https://github.com/gforge/subscription_example/tree/express-graphql Unfortunately the subscriptions don't work. Subscriptions does though not seem to be a feature of express-graphql, the example solution I found feels rather hacky.
Btw - the @ts-ignore is needed as the res isn't a full response variable. We should probably loosen that assumption in an upcoming fix.
I'm also no expert in express-graphql but I think the key is in adding context using the the
customExecuteFn:const gqlServer = graphqlHTTP({ schema, graphiql: true, customExecuteFn: ({ contextValue: req, ...rest }: ExecutionArgs) => // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore execute({ ...rest, contextValue: buildContext({ req, res: {} }) }), });I created a test-branch for express-graphql here: https://github.com/gforge/subscription_example/tree/express-graphql Unfortunately the subscriptions don't work. Subscriptions does though not seem to be a feature of express-graphql, the example solution I found feels rather hacky.
Btw - the @ts-ignore is needed as the
resisn't a full response variable. We should probably loosen that assumption in an upcoming fix.
This is correct. If you use the context property for express-graphql it is only created once. If you need to recreate your context many times, you should do so in the custom execution function.