Sha256: 6ce4ee268e2da21f1a8e2b9e62367d4fa91f1c6dd14436a82b238888a6249c71

Contents?: true

Size: 1.34 KB

Versions: 41

Compression:

Stored size: 1.34 KB

Contents

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, next_middleware)
        next_middleware.call
      rescue StandardError => err
        GraphQL::ExecutionError.new(MESSAGE)
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.5 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.4 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.3 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.2 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.1 lib/graphql/schema/catchall_middleware.rb
graphql-1.2.0 lib/graphql/schema/catchall_middleware.rb
graphql-1.1.0 lib/graphql/schema/catchall_middleware.rb
graphql-1.0.0 lib/graphql/schema/catchall_middleware.rb
graphql-0.19.4 lib/graphql/schema/catchall_middleware.rb
graphql-0.19.3 lib/graphql/schema/catchall_middleware.rb
graphql-0.19.2 lib/graphql/schema/catchall_middleware.rb
graphql-0.19.1 lib/graphql/schema/catchall_middleware.rb
graphql-0.19.0 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.15 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.14 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.13 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.12 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.11 lib/graphql/schema/catchall_middleware.rb
graphql-0.18.10 lib/graphql/schema/catchall_middleware.rb