cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Router does not work correctly with union nested types

Open flymedllva opened this issue 1 year ago • 4 comments
trafficstars

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 avatar Apr 02 '24 12:04 flymedllva

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.

github-actions[bot] avatar Apr 02 '24 12:04 github-actions[bot]

Hi,

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

Aenimus avatar Apr 03 '24 14:04 Aenimus

Is there any news on fixing this bug?

flymedllva avatar Apr 21 '24 12:04 flymedllva

Hi @flymedllva,

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

Thanks,

The WunderGraph Team

Aenimus avatar Apr 23 '24 13:04 Aenimus

fixed in [email protected]

devsergiy avatar May 28 '24 15:05 devsergiy