Sha256: a0ebf796d973cf391ac99c2a7c2a4f756029b87cd9a9f4f8cfcce613c9a49e23

Contents?: true

Size: 1.33 KB

Versions: 175

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Schema
    # 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 {GraphQL::ExecutionError}, _not_
    #   the originally-raised error.
    # - The entry in the `"errors"` key includes the location of the field
    #   which raised the errors.
    #
    # @example Use CatchallMiddleware with your schema
    #     # All errors will be suppressed and replaced with "Internal error" messages
    #     MySchema.middleware << GraphQL::Schema::CatchallMiddleware
    #
    module CatchallMiddleware
      MESSAGE = "Internal error"

      # Rescue any error and replace it with a {GraphQL::ExecutionError}
      # whose message is {MESSAGE}
      def self.call(parent_type, parent_object, field_definition, field_args, query_context)
        yield
      rescue StandardError
        GraphQL::ExecutionError.new(MESSAGE)
      end
    end
  end
end

Version data entries

175 entries across 175 versions & 2 rubygems

Version Path
graphql-1.11.12 lib/graphql/schema/catchall_middleware.rb
graphql-1.11.11 lib/graphql/schema/catchall_middleware.rb
graphql-1.12.25 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.24 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.23 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.22 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.21 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.20 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.19 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.18 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.17 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.16 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.15 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.14 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.13 lib/graphql/schema/catchall_middleware.rb
graphql_cody-1.13.0 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.12 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.11 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.10 lib/graphql/schema/catchall_middleware.rb
graphql-1.13.9 lib/graphql/schema/catchall_middleware.rb