Sha256: f8967e23a668bf79bbbef777be235461abc2b89a919282a7912f3a1bdd429af9

Contents?: true

Size: 1.64 KB

Versions: 175

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true
module GraphQL
  # If a field's resolve function returns a {ExecutionError},
  # the error will be inserted into the response's `"errors"` key
  # and the field will resolve to `nil`.
  class ExecutionError < GraphQL::Error
    # @return [GraphQL::Language::Nodes::Field] the field where the error occurred
    attr_accessor :ast_node

    # @return [String] an array describing the JSON-path into the execution
    # response which corresponds to this error.
    attr_accessor :path

    # @return [Hash] Optional data for error objects
    # @deprecated Use `extensions` instead of `options`. The GraphQL spec
    # recommends that any custom entries in an error be under the
    # `extensions` key.
    attr_accessor :options

    # @return [Hash] Optional custom data for error objects which will be added
    # under the `extensions` key.
    attr_accessor :extensions

    def initialize(message, ast_node: nil, options: nil, extensions: nil)
      @ast_node = ast_node
      @options = options
      @extensions = extensions
      super(message)
    end

    # @return [Hash] An entry for the response's "errors" key
    def to_h
      hash = {
        "message" => message,
      }
      if ast_node
        hash["locations"] = [
          {
            "line" => ast_node.line,
            "column" => ast_node.col,
          }
        ]
      end
      if path
        hash["path"] = path
      end
      if options
        hash.merge!(options)
      end
      if extensions
        hash["extensions"] = extensions.each_with_object({}) { |(key, value), ext|
          ext[key.to_s] = value
        }
      end
      hash
    end
  end
end

Version data entries

175 entries across 175 versions & 2 rubygems

Version Path
graphql-2.4.4 lib/graphql/execution_error.rb
graphql-2.4.3 lib/graphql/execution_error.rb
graphql-2.4.2 lib/graphql/execution_error.rb
graphql-2.4.1 lib/graphql/execution_error.rb
graphql-2.4.0 lib/graphql/execution_error.rb
graphql-2.3.20 lib/graphql/execution_error.rb
graphql-2.3.19 lib/graphql/execution_error.rb
graphql-2.3.18 lib/graphql/execution_error.rb
graphql-2.3.17 lib/graphql/execution_error.rb
graphql-2.3.16 lib/graphql/execution_error.rb
graphql-2.3.15 lib/graphql/execution_error.rb
graphql-2.3.14 lib/graphql/execution_error.rb
graphql-2.3.13 lib/graphql/execution_error.rb
graphql-2.3.12 lib/graphql/execution_error.rb
graphql-2.3.11 lib/graphql/execution_error.rb
graphql-2.3.10 lib/graphql/execution_error.rb
graphql-2.2.16 lib/graphql/execution_error.rb
graphql-2.1.13 lib/graphql/execution_error.rb
graphql-2.3.9 lib/graphql/execution_error.rb
graphql-2.3.8 lib/graphql/execution_error.rb