Open Yoann-Abbes opened 2 years ago
So this issue was opened in April. Did you find a solution to this? I'm running into this right now and it's looking pretty dire.
@divmgl this project is deprecated. Checkout https://github.com/graphql/express-graphql/pull/817
@divmgl No sorry, I let i go If you find a solution I would be interested too
Hi, Exact same situation here. I was digging but I think I'll migrate my code to remove this dependency :/
Trying my best to understand the exact scenario you are trying to solve & I know this library is deprecated but I run it in production with graphql-shield and battled with error handling myself so much that I patched it for our use case. Some possibly helpful tips although untested:
Instead of filtering based on the message, use a custom error with an errorType like so:
import { CustomError } from 'ts-custom-error'
export class ApiError extends CustomError {
public errorType: string
public constructor(
public code: string,
message: string,
public originalError?: Error,
) {
super(message)
this.errorType = 'ApiError'
}
}
function someResolver() {
throw new ApiError('oh_no', 'Oh No!', optionalOriginalErrorHere)
}
This will come through to your customFormatErrorFn, and you can then handle it based on the type. The next part is returning a valid GraphQL response. Look at the function graphqlMiddleware inside the the library index.ts and you will see how they construct it:
result = { data: undefined, errors: error.graphqlErrors }
I personally have a lot more custom logic painfully wired in to the library, but if you're stuck using this library, maybe it will help you find the right answer for you
This library has been deprecated and this repo will be archived soon. It has been superseded by graphql-http
.
Furthermore, if you seek a fully-featured, well-maintained and performant server - I heavily recommend GraphQL Yoga!
Hi
I'm having issues using a simple express error handler middleware to swallow errors thrown in GraphQL resolvers
For example, I would have:
GQLside
Express side
What I need, is when inside the resolver I throw the
Some Error
, Express swallows it inside it's middleware. It does not workThe only way I managed to do it, is by throwing inside the
customFormatErrorFn
function:If I do that, the Express middleware is being called.
But GraphQL returns a bad formatted response
I don't understand how I can simply manage GraphQL errors through Express. I'm certainly doing something wrong
My final goal is to catch those errors before they are sent to the client (to chose if I log them for example)