Skip to content

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

@michiomochi

Description

@michiomochi

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 🙏

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions