diff --git a/lib/graphql/client/errors.rb b/lib/graphql/client/errors.rb index bd0c3f1..ec3e47a 100644 --- a/lib/graphql/client/errors.rb +++ b/lib/graphql/client/errors.rb @@ -21,7 +21,7 @@ def self.normalize_error_paths(data = nil, errors = []) errors.each do |error| path = ["data"] current = data - error.fetch("path", []).each do |key| + error["path"].to_a.each do |key| break unless current path << key current = current[key] diff --git a/test/test_client_errors.rb b/test/test_client_errors.rb index 84bfd0f..3937d48 100644 --- a/test/test_client_errors.rb +++ b/test/test_client_errors.rb @@ -164,6 +164,28 @@ def test_normalize_error_path ] } assert_equal expected, actual + + actual = { + "data" => nil, + "errors" => [ + { + "message" => "error", + "path" => nil + } + ] + } + GraphQL::Client::Errors.normalize_error_paths(actual["data"], actual["errors"]) + expected = { + "data" => nil, + "errors" => [ + { + "message" => "error", + "path" => nil, + "normalizedPath" => %w(data), + }, + ], + } + assert_equal expected, actual end def test_filter_nested_errors_by_path