Skip to content

rescue_from isn't working due to promises #17

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

Closed
ngouy opened this issue Jan 3, 2019 · 2 comments
Closed

rescue_from isn't working due to promises #17

ngouy opened this issue Jan 3, 2019 · 2 comments

Comments

@ngouy
Copy link

ngouy commented Jan 3, 2019

Using graphql-ruby 1.8.x, I cannot rescue errors from queries as I do for mutations due to batching and its Promises. How can i Handle that ?

for mutation this is working :

class MySchema < GraphQL::Schema
    enable_preloading

    mutation Mutations::Root
    query Queries::Root

    rescue_from(Pundit::NotAuthorizedError) {
        raise GraphQL::ExecutionError, "You are forbidden to access this field."
    }
end
@nekogami
Copy link

nekogami commented Jan 22, 2019

So I ended end finding a way to make that works here's a code sample of how I do it.

class MySchema < GraphQL::Schema
  # [... query mutation subscription and plugin registry]
end


GraphQL::Errors.configure(MySchema) do
  rescue_from ActiveRecord::RecordNotFound do
    GraphQL::ExecutionError.new("Resource not found", extensions: { code: :resource_not_found })
  end
end

MySchema.enable_preloading # weird hotfix to make preload works
MySchema.graphql_definition # weird hotfix to avoid a "duplicate type declaration" error

From my understanding it is related to rmosolgo/graphql-ruby#1598

You have to call MySchema.enable_preloading at the end instead of inside the schema definition, also, I didn't try the reorder of rescue_from that they talked about since errors were already outside of the schema in our project.

@rmosolgo
Copy link

rmosolgo commented Sep 2, 2019

Hi, I just merged some new error handling for the interpreter runtime which handles promises appropriately: rmosolgo/graphql-ruby#2458

Please give it a try! If you run into a problem, please open a new issue.

Edit: sorry, I thought this was an open PR on graphql-ruby 😬

@ngouy ngouy closed this as completed Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants