Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this supported with express-graphql? #43

Closed
markgalante opened this issue Nov 21, 2020 · 4 comments
Closed

Is this supported with express-graphql? #43

markgalante opened this issue Nov 21, 2020 · 4 comments
Labels
question Issues that are just requesting information

Comments

@markgalante
Copy link

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?

@jkettmann
Copy link
Collaborator

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 😉

@jkettmann jkettmann added the question Issues that are just requesting information label Jan 6, 2021
@gforge
Copy link
Collaborator

gforge commented Aug 7, 2021

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.

@ericlewis
Copy link

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.

@ericbf
Copy link
Contributor

ericbf commented Dec 21, 2022

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.

With the above comment, it works just find with express-graphql.

Ensure you are using a customExecuteFn. In the near future, I’ll push an update that fixes up all the types so you don’t need the ignore flag, but until then, the above solution works to get you going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that are just requesting information
Projects
None yet
Development

No branches or pull requests

5 participants