Sha256: f8967e23a668bf79bbbef777be235461abc2b89a919282a7912f3a1bdd429af9

Contents?: true

Size: 1.64 KB

Versions: 180

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

180 entries across 180 versions & 2 rubygems

Version Path
graphql-1.10.8 lib/graphql/execution_error.rb
graphql-1.10.7 lib/graphql/execution_error.rb
graphql-1.10.6 lib/graphql/execution_error.rb
graphql-1.10.5 lib/graphql/execution_error.rb
graphql-1.10.4 lib/graphql/execution_error.rb
graphql-1.10.3 lib/graphql/execution_error.rb
graphql-1.10.2 lib/graphql/execution_error.rb
graphql-1.9.19 lib/graphql/execution_error.rb
graphql-1.10.1 lib/graphql/execution_error.rb
graphql-1.10.0 lib/graphql/execution_error.rb
graphql-1.10.0.pre4 lib/graphql/execution_error.rb
graphql-1.9.18 lib/graphql/execution_error.rb
graphql-1.10.0.pre3 lib/graphql/execution_error.rb
graphql-1.9.17 lib/graphql/execution_error.rb
graphql-1.10.0.pre2 lib/graphql/execution_error.rb
graphql-1.9.16 lib/graphql/execution_error.rb
graphql-1.9.15 lib/graphql/execution_error.rb
graphql-1.9.14 lib/graphql/execution_error.rb
graphql-1.10.0.pre1 lib/graphql/execution_error.rb
graphql-1.9.13 lib/graphql/execution_error.rb