-
Notifications
You must be signed in to change notification settings - Fork 1.4k
GraphQL::Execution::Interpreter and rescue_from compatibility #2139
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
Comments
A bit off topic but as far as I know you can't pass a error class object to |
@masakazutakewaka-stt Yes indeed, I based myself off this gem we currently use: https://github.com/exAspArk/graphql-errors I'll update the issue since I think that graphql-errors should be in graphql-ruby |
@JanStevens Cool gem (It seems it doesn't support class-based API though) . I looked it up and totally agree with you. It would be really awesome if graphql-ruby gets to support behavior like this ↓ where unhandled errors are rescued with an custom error class object. rescue_from StandardError do |e|
CustomError.new(e)
end |
@rmosolgo, thoughts on this? |
Do you have any updates? |
Hi, sorry I haven't written back sooner 😞 ! My thoughts are:
🤔 Maybe we could make graphql-errors support the new runtime. I see right now it uses a field instrumenter, which is no longer supported. It would almost work as a graphql-ruby/lib/graphql/schema/field_extension.rb Lines 42 to 51 in 272e36e
But I'm not sure exactly how to rescue errors from promises there. I will make some time for an investigation on that and write back here! |
Any updates or thoughts on this? It seems like this PR is very close to working in the graphql-errors repo. https://github.com/exAspArk/graphql-errors/pull/18/files |
Hi! I'm in the same situation, enabled the new interpreter to have subscriptions and my What I'm doing right now is simply on tracer ErrorHandlingTracer and the class is: class ErrorHandlingTracer
def self.trace(key, data)
yield
rescue Sequel::ValidationFailed => error_1
GraphQL::ExecutionError.new(error_1.message)
rescue Some other error => error_2
extensions = error_2.extra_data.is_a?(Hash) ? error_2.extra_data : {}
GraphQL::ExecutionError.new(error_2.message, extensions: extensions)
end
end |
@thiago-sydow , I think that's a great solution, thanks for sharing! I don't think there will be much performance impact for it. |
Hi, thanks to all who shared their thoughts here. I've added some new error handling which you can try on master: #2458 If you give a try and encounter a problem, please open a new issue! |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
As documented here the new
GraphQL::Execution::Interpreter
does not work with therescue_from
middleware. I think the rescue_from add valuable error handeling that allows your endpoint to always return a 200 and indicate the errors. The following examples are based of thegraphql-errors
gem which we currently use https://github.com/exAspArk/graphql-errorsThe most common example is catching
ActiveRecord::RecordNotFound
and replace them withnil
so whenever you try to fetch something that does not exist you return a 200 with nothing in it.Another example is to error standardisation, for example in our GraphQL api we always call
update!
orsave!
this raises aActiveRecord::RecordInvalid
which we capture with rescue_from and standarize the error response:Ofcourse one can say that every mutation / resolver should deal with the errors themself, but this means that you always have to go for a
if ...save else do_with_errors end
kind of thing which isn't that pretty nor ensures consistency.Finally sometimes (even when you know its bad) you have some deeply nested code where you want to brake out of so your only resort is to raise an exception, this does not mean you want to return back a 500 but rather a customised message.
If anyone else has other use cases then please do share,
Regards
The text was updated successfully, but these errors were encountered: