Skip to content

Commit 0305911

Browse files
authored
Merge pull request #4 from wuarmin/fix_normalize_error_paths
Fix normalize error paths
2 parents a518a47 + 82d23ac commit 0305911

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/graphql/client/errors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def self.normalize_error_paths(data = nil, errors = [])
2121
errors.each do |error|
2222
path = ["data"]
2323
current = data
24-
error.fetch("path", []).each do |key|
24+
error["path"].to_a.each do |key|
2525
break unless current
2626
path << key
2727
current = current[key]

test/test_client_errors.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ def test_normalize_error_path
164164
]
165165
}
166166
assert_equal expected, actual
167+
168+
actual = {
169+
"data" => nil,
170+
"errors" => [
171+
{
172+
"message" => "error",
173+
"path" => nil
174+
}
175+
]
176+
}
177+
GraphQL::Client::Errors.normalize_error_paths(actual["data"], actual["errors"])
178+
expected = {
179+
"data" => nil,
180+
"errors" => [
181+
{
182+
"message" => "error",
183+
"path" => nil,
184+
"normalizedPath" => %w(data),
185+
},
186+
],
187+
}
188+
assert_equal expected, actual
167189
end
168190

169191
def test_filter_nested_errors_by_path

0 commit comments

Comments
 (0)