Exception: GraphWeaver::QueryError

Inherits:
Error
  • Object
show all
Includes:
ErrorFiltering
Defined in:
lib/graph_weaver/errors.rb

Overview

Raised when a GraphQL response carried top-level errors and the caller demanded data (Response#data!, or the one-shot GraphWeaver.execute). Carries the structured errors, any partial data, and top-level extensions (cost/throttle metadata).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorFiltering

#each_error, #entity_id, #errors_at, #errors_by_field, #report, #schema_stale?

Constructor Details

#initialize(errors, data: nil, extensions: {}) ⇒ QueryError

Returns a new instance of QueryError.



254
255
256
257
258
259
# File 'lib/graph_weaver/errors.rb', line 254

def initialize(errors, data: nil, extensions: {})
  @errors = errors
  @data = data
  @extensions = extensions
  super(summary)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



252
253
254
# File 'lib/graph_weaver/errors.rb', line 252

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



252
253
254
# File 'lib/graph_weaver/errors.rb', line 252

def errors
  @errors
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



252
253
254
# File 'lib/graph_weaver/errors.rb', line 252

def extensions
  @extensions
end

Instance Method Details

#codesObject

All non-nil error codes — handy for codes.include?("THROTTLED").



262
263
264
# File 'lib/graph_weaver/errors.rb', line 262

def codes
  errors.map(&:code).compact
end

#to_hObject

The machine side: every error with its path/code/extensions, plus the drift verdict — nest this straight into a JSON response.



268
269
270
271
272
273
274
275
# File 'lib/graph_weaver/errors.rb', line 268

def to_h
  super.merge(
    "schema_stale" => schema_stale?,
    "codes" => codes,
    "errors" => errors.map(&:to_h),
    "extensions" => extensions,
  )
end