Skip to content

TypeError in normalize_error_paths with federated routers #78

@tlubz

Description

@tlubz

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:

current = current[key]

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

Reproducing the error:

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:

[{"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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions