Skip to content

Case of GraphQL::Schema.rescue_from doesn't work #1598

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
michiomochi opened this issue Jun 19, 2018 · 6 comments
Closed

Case of GraphQL::Schema.rescue_from doesn't work #1598

michiomochi opened this issue Jun 19, 2018 · 6 comments

Comments

@michiomochi
Copy link

michiomochi commented Jun 19, 2018

graphql-ruby version is v1.8.3.
rescue_from doesn't work when there is a query or mutation definition before rescue_from.

Implement

NG

class TestSchema < GraphQL::Schema
  〜
  query Types::Query
  mutation Types::Mutation

  rescue_from(Exception) do |error|
    # doesn't call
  end
〜

OK

class TestSchema < GraphQL::Schema
  〜
  rescue_from(Exception) do |error|
    # call
  end

  query Types::Query
  mutation Types::Mutation
〜

Reason

rescue_from is following code.

def rescue_from(err_class, &handler_block)
  @rescues ||= {}
  @rescues[err_class] = handler_block
end

And, query and mutation are affected by @rescues. (maybe)

Please check 🙏

@michiomochi michiomochi changed the title Case of GraphQL::Schema.rescue_from doesn't work well Case of GraphQL::Schema.rescue_from doesn't work Jun 19, 2018
@rmosolgo
Copy link
Owner

How strange! Thanks for opening this issue and sharing your work-around.

@mcdave029
Copy link
Contributor

Any Updates here? both implementations are not working with me too. 😅

@modosc
Copy link
Contributor

modosc commented Oct 17, 2018

i noticed the same thing and (at least for us) it was related to graphql-preload. having enable_preloading inside of our schema class definition broke rescue_from behavior (both the built-in and from graphql-errors. making a call to enable_preloading outside of the class (ie, MySchema.enable_preloading) seems to resolve it but i'm not sure why.

@jonathanheron
Copy link

jonathanheron commented Oct 29, 2018

@modosc I see the same problematic behaviour when using graphql-preload and including enable_preloading inside the schema class definition.

However, when I move MySchema.enable_preloading to anywhere else in my code, I see the same issue. Where are you calling MySchema.enable_preloading in a way that resolves the problem?

thanks

@nekogami
Copy link

@jonathanheron Since it's been 4 months, I don't know if you solved your issue but I ended finding a solution that worked on my project here ConsultingMD/graphql-preload#17 (comment)

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 2, 2019

I just added new error handling for the interpreter runtime here: #2458 I think it should work with any order of schema configuration, since it doesn't touch the .graphql_definition compatibility layer.

If you give it a try and run into trouble, please open a new issue!

@rmosolgo rmosolgo closed this as completed Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants