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

Duplicate __typename in response for nested union queries #3374

Open
dkempner opened this issue Nov 14, 2024 · 1 comment
Open

Duplicate __typename in response for nested union queries #3374

dkempner opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dkempner
Copy link

dkempner commented Nov 14, 2024

What happened?

When running a query with this shape, the response that's returned is technically not valid JSON because it has duplicate __typename properties.

Query

query {
  union {
    __typename
    ... on A {
      __typename
    }
    ... on B {
      __typename
    }
  }
}

Response

{
    "data": {
        "union": [
            {
                "__typename": "A",
                "__typename": "A"
            },
            {
                "__typename": "B",
                "__typename": "B"
            }
        ]
    }
}

What did you expect?

Duplicate properties should be deduplicated.

Minimal graphql.schema and models to reproduce

  1. Clone https://github.com/dkempner/gqlgen-union-double-typename
  2. go run server.go
  3. Visit http://localhost:8080/
  4. Open Chrome devtools to network tab
  5. Execute the query saved in repro.grapqhl
  6. Observe the "Response" tab has duplicate __typename properties
image

versions

  • go run github.com/99designs/gqlgen version?
    • v0.17.56
  • go version?
    • go version go1.23.3 darwin/arm64
@dkempner dkempner changed the title Selecting __typename outside of a union and inside of a union results in duplicate __typename in response Selecting __typename outside of a union and inside of a union results in duplicate __typename in response Nov 14, 2024
@dkempner dkempner changed the title Selecting __typename outside of a union and inside of a union results in duplicate __typename in response Duplicate __typename in response for nested union queries Nov 14, 2024
@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Nov 15, 2024

Oh, wow. Yeah, that's definitely a bug. Thanks for reporting, and if you get a chance, I would love a PR to fix.

@StevenACoffman StevenACoffman added bug Something isn't working help wanted Extra attention is needed labels Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants