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

TypeError in `normalize_error_paths` with federated routers

Aperta
#78 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Ruby
Stelle
78
Fork
228
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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"]}]
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia in graphql/client/errors.rb, in Errors.normalize_error_paths, ed esegui la riproduzione fornita con il percorso federato "@". Confrontala con l'esempio con indice intero; il lavoro è completato quando il caso "@" restituisce il normalizedPath previsto senza sollevare TypeError, mentre il caso intero continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
graphql, ruby
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.