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

Implement after hook or error handling? #11

Closed
pyrossh opened this issue Nov 24, 2017 · 4 comments · Fixed by #77
Closed

Implement after hook or error handling? #11

pyrossh opened this issue Nov 24, 2017 · 4 comments · Fixed by #77

Comments

@pyrossh
Copy link

pyrossh commented Nov 24, 2017

Right now I generate and start a transaction in the context function and if the graphql request fails due to an error I would like inspect the result if it has any errors and based on that to rollback/commit the transaction. It would be nice if we could have a function similar to context but gets called after the graphql function to clean up connections/log stuff etc.

It seems apollo-server-express already exposes this in the options
If there could be some way we can pass the apollo server options directly to it using yoga for customizing the apollo server used underneath.

@pyrossh
Copy link
Author

pyrossh commented Nov 24, 2017

Also it seems if an error occurs in the context function. It crashes the server. Currently my context function is async and checks the token. It would be great if could try to catch an error happening here and return it as a graphql error.

@orefalo
Copy link

orefalo commented Nov 29, 2017

+1 same issue

On the implementation, I think you can better structure the Option type. Also a log level is better than a boolean.

  • formatError?: Function
  • formatParams?: Function
  • formatResponse?: Function
  • logFunction?: LogFunction
  • debug?: boolean

@pyrossh
Copy link
Author

pyrossh commented Nov 30, 2017

I've removed the debug option. I've put these new params in the props will/should it be in the options or should it be in a new field called apollo which will expose all low level apollo server options.

export interface Props {
  typeDefs?: string
  resolvers?: IResolvers
  schema?: GraphQLSchema
  context?: Context | ContextCallback
  options?: Options
  formatError?: Function
  formatParams?: Function
  formatResponse?: Function
  logFunction?: LogFunction
}

kbrandwijk added a commit that referenced this issue Jan 5, 2018
BREAKING CHANGES: constructor and start options have changed

Closes #11, closes #16, closes #71
kbrandwijk added a commit that referenced this issue Jan 5, 2018
BREAKING CHANGES: constructor and start options have changed

Closes #11, closes #16, closes #71
@Urigo
Copy link
Collaborator

Urigo commented Mar 29, 2022

Hey, @Urigo from The Guild here!

You might know us from projects such as graphql-code-generator, envelop or graphql-tools.

For a long time we thought that the Javascript ecosystem is still missing a lightweight cross-platform, but still highly customizable GraphQL Server.

In the past the awesome Prisma team took on that great challenge and now we are happy to announce that we are continuing them and just released GraphQL Yoga 2.0 - Build fast, extensible, and batteries-included (Subscriptions, Serverless, File uploads support) GraphQL APIs in Node.js 🚀

And regarding the issue here, Yoga uses the Envelop plugin system under the hood which has a very powerful hooks system and a whole ecosystem of plugins, including error handling plugins:

https://www.envelop.dev/plugins
https://www.the-guild.dev/blog/graphql-error-handling-with-fp

We have been working a long time on version 2.0 and have been using it in our clients projects for a few months now and shared a couple of alpha cycles here.
Thank you all for your feedback and suggestions, you made this release possible!

Please try Yoga out again, give us feedback and help us spread the word on the new release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants