Module: GraphQL::Schema::CatchallMiddleware Private

Defined in:
lib/graphql/schema/catchall_middleware.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

In early GraphQL versions, errors would be “automatically” rescued and replaced with "Internal error". That behavior was undesirable but this middleware is offered for people who want to preserve it.

It has a couple of differences from the previous behavior:

  • Other parts of the query will be run (previously, execution would stop when the error was raised and the result would have no "data" key at all)
  • The entry in Query::Context#errors is a ExecutionError, not the originally-raised error.
  • The entry in the "errors" key includes the location of the field which raised the errors.

Examples:

Use CatchallMiddleware with your schema

# All errors will be suppressed and replaced with "Internal error" messages
MySchema.middleware << GraphQL::Schema::CatchallMiddleware

Constant Summary

MESSAGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Internal error"

Class Method Summary collapse

Class Method Details

.call(parent_type, parent_object, field_definition, field_args, query_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rescue any error and replace it with a ExecutionError whose message is MESSAGE



28
29
30
31
32
# File 'lib/graphql/schema/catchall_middleware.rb', line 28

def self.call(parent_type, parent_object, field_definition, field_args, query_context)
  yield
rescue StandardError
  GraphQL::ExecutionError.new(MESSAGE)
end