Sha256: 5983359a3fe22dfe568a851c0555d18ffd3e4560a4eff231b7f855ce66400abd

Contents?: true

Size: 960 Bytes

Versions: 15

Compression:

Stored size: 960 Bytes

Contents

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

15 entries across 15 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/execution_error.rb
graphql-1.2.5 lib/graphql/execution_error.rb
graphql-1.2.4 lib/graphql/execution_error.rb
graphql-1.2.3 lib/graphql/execution_error.rb
graphql-1.2.2 lib/graphql/execution_error.rb
graphql-1.2.1 lib/graphql/execution_error.rb
graphql-1.2.0 lib/graphql/execution_error.rb
graphql-1.1.0 lib/graphql/execution_error.rb
graphql-1.0.0 lib/graphql/execution_error.rb
graphql-0.19.4 lib/graphql/execution_error.rb
graphql-0.19.3 lib/graphql/execution_error.rb
graphql-0.19.2 lib/graphql/execution_error.rb
graphql-0.19.1 lib/graphql/execution_error.rb
graphql-0.19.0 lib/graphql/execution_error.rb
graphql-0.18.15 lib/graphql/execution_error.rb