Method: GraphQL::Client::Errors.normalize_error_paths

Defined in:
lib/graphql/client/errors.rb

.normalize_error_paths(data = nil, errors = []) ⇒ Object

Internal: Normalize GraphQL Error “path” ensuring the path exists.

Records “normalizedPath” value to error object.

data - Hash of response data errors - Array of error Hashes

Returns nothing.


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/client/errors.rb', line 20

def self.normalize_error_paths(data = nil, errors = [])
  errors.each do |error|
    path = ["data"]
    current = data
    error.fetch("path", []).each do |key|
      break unless current
      path << key
      current = current[key]
    end
    error["normalizedPath"] = path
  end
  errors
end