Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router does not work correctly with union nested types #679

Closed
flymedllva opened this issue Apr 2, 2024 · 5 comments
Closed

Router does not work correctly with union nested types #679

flymedllva opened this issue Apr 2, 2024 · 5 comments
Assignees
Labels
bug Something isn't working confirmed bug The issue was replicated/determined to be a bug. engine-planner internally-reviewed The issue has been reviewed internally. router

Comments

@flymedllva
Copy link

flymedllva commented Apr 2, 2024

Component(s)

router, controlplane, composition, cli

Component version

v0.78.0

wgc version

0.44.1

controlplane version

v0.80.0

router version

v0.78.0

What happened?

Description

We have a large 15 megabyte supergraph running Apollo, we tried to run Cosmo on it and got a lot of union related errors.
We tried to reproduce them, there seems to be a problem with the

  • nested types in union
  • identical fields in union types
  • possibly null union types (but it's not certain)

Steps to Reproduce

I've put together a minimal example that the latest version of the router doesn't work with
https://github.com/flymedllva/cosmo-union-with-nested-type-does-not-work

example query:

query Test {
  unions {
    abUnion {
      __typename
      ... on A {
        ...AFragment
      }
      ... on B {
        ...BFragment
      }
    }
  }
}

fragment AFragment on A {
  __typename
  common {
    test
  }
}

fragment BFragment on B {
  __typename
  common {
    broken
  }
}

Expected Result

{
  "data": {
    "unions": [
      {
        "abUnion": {
          "__typename": "A",
          "common": {
            "test": 1
          }
        }
      },
      {
        "abUnion": {
          "__typename": "A",
          "common": {
            "test": 1
          }
        }
      }
    ]
  }
}

Actual Result

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field 'Query.unions.abUnion.common.broken'.",
      "path": [
        "unions",
        0,
        "abUnion",
        "common",
        "broken"
      ]
    }
  ],
  "data": null,
  "extensions": {
    "trace": {
      "info": {
        "trace_start_time": "2024-04-02T14:58:58+03:00",
        "trace_start_unix": 1712059138,
        "parse_stats": {
          "duration_nanoseconds": 388625,
          "duration_pretty": "388.625µs",
          "duration_since_start_nanoseconds": 157625,
          "duration_since_start_pretty": "157.625µs"
        },
        "normalize_stats": {
          "duration_nanoseconds": 739167,
          "duration_pretty": "739.167µs",
          "duration_since_start_nanoseconds": 565167,
          "duration_since_start_pretty": "565.167µs"
        },
        "validate_stats": {
          "duration_nanoseconds": 113292,
          "duration_pretty": "113.292µs",
          "duration_since_start_nanoseconds": 1314625,
          "duration_since_start_pretty": "1.314625ms"
        },
        "planner_stats": {
          "duration_nanoseconds": 4123166,
          "duration_pretty": "4.123166ms",
          "duration_since_start_nanoseconds": 1428584,
          "duration_since_start_pretty": "1.428584ms"
        }
      },
      "fetch": {
        "id": "335d69f3-9d4b-4d9d-8e1e-7b307be6c3bc",
        "type": "single",
        "path": "query",
        "data_source_id": "0",
        "datasource_load_trace": {
          "raw_input_data": {},
          "input": {
            "body": {
              "query": "{unions {abUnion {__typename ... on A {__typename common {test}} ... on B {__typename common {broken}}}}}"
            },
            "header": {},
            "method": "POST",
            "url": "http://localhost:8080/query"
          },
          "output": {
            "data": {
              "unions": [
                {
                  "abUnion": {
                    "__typename": "A",
                    "common": {
                      "test": 1
                    }
                  }
                },
                {
                  "abUnion": {
                    "__typename": "A",
                    "common": {
                      "test": 1
                    }
                  }
                }
              ]
            },
            "extensions": {
              "trace": {
                "request": {
                  "method": "POST",
                  "url": "http://localhost:8080/query",
                  "headers": {
                    "Accept": [
                      "application/json"
                    ],
                    "Accept-Encoding": [
                      "gzip",
                      "deflate"
                    ],
                    "Content-Type": [
                      "application/json"
                    ],
                    "Myheader": [
                      ""
                    ]
                  }
                },
                "response": {
                  "status_code": 200,
                  "status": "200 OK",
                  "headers": {
                    "Content-Length": [
                      "157"
                    ],
                    "Content-Type": [
                      "application/json"
                    ],
                    "Date": [
                      "Tue, 02 Apr 2024 11:58:58 GMT"
                    ]
                  },
                  "body_size": 157
                }
              }
            }
          },
          "duration_since_start_nanoseconds": 6022500,
          "duration_since_start_pretty": "6.0225ms",
          "duration_load_nanoseconds": 4066125,
          "duration_load_pretty": "4.066125ms",
          "single_flight_used": true,
          "single_flight_shared_response": false,
          "load_skipped": false,
          "load_stats": {
            "get_conn": {
              "duration_since_start_nanoseconds": 6902750,
              "duration_since_start_pretty": "6.90275ms",
              "host_port": "localhost:8080"
            },
            "got_conn": {
              "duration_since_start_nanoseconds": 6931834,
              "duration_since_start_pretty": "6.931834ms",
              "reused": true,
              "was_idle": true,
              "idle_time_nanoseconds": 811850625,
              "idle_time_pretty": "811.850625ms"
            },
            "got_first_response_byte": {
              "duration_since_start_nanoseconds": 7545042,
              "duration_since_start_pretty": "7.545042ms"
            },
            "dns_start": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": "",
              "host": ""
            },
            "dns_done": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": ""
            },
            "connect_start": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": "",
              "network": "",
              "addr": ""
            },
            "connect_done": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": "",
              "network": "",
              "addr": ""
            },
            "tls_handshake_start": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": ""
            },
            "tls_handshake_done": {
              "duration_since_start_nanoseconds": 0,
              "duration_since_start_pretty": ""
            },
            "wrote_headers": {
              "duration_since_start_nanoseconds": 7048834,
              "duration_since_start_pretty": "7.048834ms"
            },
            "wrote_request": {
              "duration_since_start_nanoseconds": 7067667,
              "duration_since_start_pretty": "7.067667ms"
            }
          }
        }
      },
      "node_type": "object",
      "nullable": true,
      "fields": [
        {
          "name": "unions",
          "value": {
            "node_type": "array",
            "path": [
              "unions"
            ],
            "items": [
              {
                "node_type": "object",
                "nullable": true,
                "fields": [
                  {
                    "name": "abUnion",
                    "value": {
                      "node_type": "object",
                      "path": [
                        "abUnion"
                      ],
                      "fields": [
                        {
                          "name": "__typename",
                          "value": {
                            "node_type": "string",
                            "path": [
                              "__typename"
                            ],
                            "is_type_name": true
                          },
                          "parent_type_names": [
                            "ABUnion",
                            "A",
                            "B"
                          ],
                          "named_type": "String",
                          "data_source_ids": [
                            "0"
                          ]
                        },
                        {
                          "name": "common",
                          "value": {
                            "node_type": "object",
                            "path": [
                              "common"
                            ],
                            "fields": [
                              {
                                "name": "test",
                                "value": {
                                  "node_type": "integer",
                                  "path": [
                                    "test"
                                  ]
                                },
                                "parent_type_names": [
                                  "CommonA"
                                ],
                                "named_type": "Int",
                                "data_source_ids": [
                                  "0"
                                ]
                              },
                              {
                                "name": "broken",
                                "value": {
                                  "node_type": "integer",
                                  "path": [
                                    "broken"
                                  ]
                                },
                                "parent_type_names": [
                                  "CommonB"
                                ],
                                "named_type": "Int",
                                "data_source_ids": [
                                  "0"
                                ]
                              }
                            ]
                          },
                          "parent_type_names": [
                            "A",
                            "B"
                          ],
                          "named_type": "CommonA",
                          "data_source_ids": [
                            "0"
                          ]
                        }
                      ]
                    },
                    "parent_type_names": [
                      "Unions"
                    ],
                    "named_type": "ABUnion",
                    "data_source_ids": [
                      "0"
                    ]
                  }
                ]
              }
            ]
          },
          "parent_type_names": [
            "Query"
          ],
          "named_type": "Unions",
          "data_source_ids": [
            "0"
          ]
        }
      ]
    }
  }
}

Environment information

Environment

OS: 14.4 (23E214)
Package Manager: npm
Compiler(if manually compiled): go version go1.22.1 darwin/arm64

Router configuration

version: "1"

# General router options
graph:
  name: "production"
  token: ""

log_level: "info"
listen_addr: "localhost:3002"
playground_enabled: true
introspection_enabled: true
json_log: true
shutdown_delay: 15s
grace_period: 20s
poll_interval: 10s
health_check_path: "/health"
readiness_check_path: "/health/ready"
liveness_check_path: "/health/live"
router_config_path: "config.json"

cors:
  allow_origins: ["*"]
  allow_methods:
    - HEAD
    - GET
    - POST
  allow_headers:
    - Origin
    - Content-Length
    - Content-Type
  allow_credentials: true
  max_age_minutes: 5m

# Config for custom modules   
# See "https://cosmo-docs.wundergraph.com/router/custom-modules" for more information   
modules:
  myModule:
    # Arbitrary values, unmarshalled by the module
    value: 1

Router execution config

No response

Log output

No response

Additional context

Screenshot 2024-04-02 at 15 36 42
Screenshot 2024-04-02 at 15 37 08

@flymedllva flymedllva added the bug Something isn't working label Apr 2, 2024
Copy link

github-actions bot commented Apr 2, 2024

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible.
The roadmap is driven by our customers and we have to prioritize issues that are important to them.
You can influence the priority by becoming a customer. Please contact us here.

@devsergiy devsergiy added internally-reviewed The issue has been reviewed internally. confirmed bug The issue was replicated/determined to be a bug. router labels Apr 3, 2024
@Aenimus
Copy link
Member

Aenimus commented Apr 3, 2024

Hi,

We're aware of this issue. We will provide updates when possible.

@flymedllva
Copy link
Author

Is there any news on fixing this bug?

@Aenimus
Copy link
Member

Aenimus commented Apr 23, 2024

Hi @flymedllva,

It's still in progress. As I mentioned, we will update when possible.

Thanks,

The WunderGraph Team

@devsergiy
Copy link
Member

fixed in router@0.90.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug The issue was replicated/determined to be a bug. engine-planner internally-reviewed The issue has been reviewed internally. router
Projects
None yet
Development

No branches or pull requests

3 participants