Sha256: 2e93e0f863d2dbdac58392e78ad03289f5bf24230bfe665ea40d17b84c603147

Contents?: true

Size: 1.14 KB

Versions: 23

Compression:

Stored size: 1.14 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 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

    # @return [Hash] Optional data for error objects
    attr_accessor :options

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql-1.8.0 lib/graphql/execution_error.rb
graphql-1.8.0.pre11 lib/graphql/execution_error.rb
graphql-1.8.0.pre10 lib/graphql/execution_error.rb
graphql-1.7.14 lib/graphql/execution_error.rb
graphql-1.8.0.pre9 lib/graphql/execution_error.rb
graphql-1.8.0.pre8 lib/graphql/execution_error.rb
graphql-1.7.13 lib/graphql/execution_error.rb
graphql-1.8.0.pre7 lib/graphql/execution_error.rb
graphql-1.7.12 lib/graphql/execution_error.rb
graphql-1.7.11 lib/graphql/execution_error.rb
graphql-1.7.10 lib/graphql/execution_error.rb
graphql-1.8.0.pre6 lib/graphql/execution_error.rb
graphql-1.8.0.pre5 lib/graphql/execution_error.rb
graphql-1.7.9 lib/graphql/execution_error.rb
graphql-1.8.0.pre4 lib/graphql/execution_error.rb
graphql-1.8.0.pre3 lib/graphql/execution_error.rb
graphql-1.7.8 lib/graphql/execution_error.rb
graphql-1.8.0.pre2 lib/graphql/execution_error.rb
graphql-1.7.7 lib/graphql/execution_error.rb
graphql-1.8.0.pre1 lib/graphql/execution_error.rb