Skip to content

Commit

Permalink
Merge pull request #4 from wuarmin/fix_normalize_error_paths
Browse files Browse the repository at this point in the history
Fix normalize error paths
  • Loading branch information
rmosolgo committed Jan 25, 2024
2 parents a518a47 + 82d23ac commit 0305911
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphql/client/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 22 additions & 0 deletions test/test_client_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0305911

Please sign in to comment.