github-community-projects / github-community-projects/graphql-client

TypeError in `normalize_error_paths` with federated routers

Open
#78 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
78
Forks
228
PR merge metrics
No merged PRs in 30d

Description

We are using WunderGraph's Cosmo Router for GraphQL federation. When the resolver fails to bulk load data in an array context from a federated subgraph, the router will include an `@` in the error paths for those errors, instead of an array index integer. From my research, this is semi-standard with federated routers like Cosmo and Apollo Router. When processing the response in these cases, the graphql client will fail with the following error:

```
TypeError: no implicit conversion of String into Integer
--
0: ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:27:in `block (2 levels) in normalize_error_paths'
1: ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:24:in `each'
2: ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:24:in `block in normalize_error_paths'
3: ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:21:in `each'
4: ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:21:in `normalize_error_paths'
...
```

it's happening on this line in `Errors.normalize_error_paths` while validating the paths exist in the data:

```ruby
current = current[key]
```

in this context, `current` is an array, but `key` is `"@"`, which is causing a type error.

## Reproducing the error:

```ruby
errs_with_at = [{"message"=>"boom", "locations"=>[{"line"=>1, "column"=>113}], "path"=>["records", "@", "item"]}]
GraphQL::Client::Errors.normalize_error_paths({"records"=>[{"item"=>nil}]}, errs_with_at)
```

### Expected result:

```ruby
[{"message"=>"boom", "locations"=>[{"line"=>1, "column"=>113}], "path"=>["records", "@", "item"], "normalizedPath"=>["data", "records", "@", "item"]}]
```

### Actual result

```
TypeError: no implicit conversion of String into Integer
from /Users/tlubitz/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/graphql-client-0.26.0/lib/graphql/client/errors.rb:27:in `block (2 levels) in normalize_error_paths'
```

By contrast, the same invocation works if you replace `"@"` with e.g. `0`:

```ruby
errs = [{"message"=>"boom", "locations"=>[{"line"=>1, "column"=>113}], "path"=>["records", 0, "item"], "normalizedPath"=>["data", "records", 0, "item"]}]
GraphQL::Client::Errors.normalize_error_paths({"records"=>[{"item"=>nil}]}, errs)

[{"message"=>"boom", "locations"=>[{"line"=>1, "column"=>113}], "path"=>["records", 0, "item"], "normalizedPath"=>["data", "records", 0, "item"]}]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.