Sha256: 095b9dd82ef95d9f0971ae4144e4230dc9f6241c51dd7dfbcbc4fdc924bc6d02

Contents?: true

Size: 990 Bytes

Versions: 34

Compression:

Stored size: 990 Bytes

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 occured
    attr_accessor :ast_node

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

    def initialize(message, ast_node: nil)
      @ast_node = ast_node
      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
      hash
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
graphql-1.7.3 lib/graphql/execution_error.rb
graphql-1.7.2 lib/graphql/execution_error.rb
graphql-1.7.1 lib/graphql/execution_error.rb
graphql-1.7.0 lib/graphql/execution_error.rb
graphql-1.6.8 lib/graphql/execution_error.rb
graphql-1.6.7 lib/graphql/execution_error.rb
graphql-1.6.6 lib/graphql/execution_error.rb
graphql-1.6.5 lib/graphql/execution_error.rb
graphql-1.6.4 lib/graphql/execution_error.rb
graphql-1.5.15 lib/graphql/execution_error.rb
graphql-1.6.3 lib/graphql/execution_error.rb
graphql-1.6.2 lib/graphql/execution_error.rb
graphql-1.6.1 lib/graphql/execution_error.rb
graphql-1.6.0 lib/graphql/execution_error.rb
graphql-1.5.14 lib/graphql/execution_error.rb
graphql-1.5.13 lib/graphql/execution_error.rb
graphql-1.5.7.1 lib/graphql/execution_error.rb
graphql-1.5.12 lib/graphql/execution_error.rb
graphql-1.5.11 lib/graphql/execution_error.rb
graphql-1.5.10 lib/graphql/execution_error.rb