graphql-passport icon indicating copy to clipboard operation
graphql-passport copied to clipboard

Is this supported with express-graphql?

Open markgalante opened this issue 4 years ago • 3 comments
trafficstars

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?

markgalante avatar Nov 21 '20 19:11 markgalante

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:

jkettmann avatar Jan 06 '21 09:01 jkettmann

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.

gforge avatar Aug 07 '21 08:08 gforge

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.

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.

ericlewis avatar Nov 09 '21 17:11 ericlewis