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

xgql does not deduplicate query keys #78

Closed
negz opened this issue Jun 9, 2021 · 6 comments · Fixed by #85
Closed

xgql does not deduplicate query keys #78

negz opened this issue Jun 9, 2021 · 6 comments · Fixed by #85
Labels
bug Something isn't working needs-epic-link Needs a link to an epic needs-points-label Needs a story points label needs-project Needs to be added to a project board

Comments

@negz
Copy link
Member

negz commented Jun 9, 2021

What happened?

{
  kubernetesResource(id: "Hi8wQzg9X0M4XYY8YVZQVQE") {
    metadata {
      name
    }
    ... on CompositeResourceDefinition {
      metadata {
        uid
      }
    }
  }
}

Yields this:

{
  "data": {
    "kubernetesResource": {
      "metadata": {
        "name": "compositeclusters.aws.platformref.crossplane.io"
      },
      "metadata": {
        "uid": "a8dcfa8e-3909-4bf8-968b-64c65ca9b65b"
      }
    }
  }
}

Which is invalid JSON and should yield this:

{
  "data": {
    "kubernetesResource": {
      "metadata": {
        "name": "compositeclusters.aws.platformref.crossplane.io",
        "uid": "a8dcfa8e-3909-4bf8-968b-64c65ca9b65b"
      }
    }
  }
}

This may be related 99designs/gqlgen#1311.

How can we reproduce it?

Make the query above.

What environment did it happen in?

@negz negz added bug Something isn't working needs-project Needs to be added to a project board needs-epic-link Needs a link to an epic needs-points-label Needs a story points label labels Jun 9, 2021
@negz
Copy link
Member Author

negz commented Jun 10, 2021

I tried this with 99designs/gqlgen@5ad012e, which is the latest commit in master at the time of writing. It appears to fix the problem of returning duplicate keys, but it does so by having the inline fragment override the more generic part of the query rather than merging them. That is, if I query:

query {
  kubernetesResource(
    id: "Xf5rXAL-UHvndETH56dPJgA5XXvndEQ5PV9DOf4zbf43O1X_Bzg1MDkxNzM"
  ) {
    metadata {
      name
    }
  }
}

I get this response:

{
  "data": {
    "kubernetesResource": {
      "metadata": {
        "name": "crossplane-provider-aws-3b7ef8509173"
      }
    }
  },
  "extensions": {}
}

However if I query:

query {
  kubernetesResource(
    id: "Xf5rXAL-UHvndETH56dPJgA5XXvndEQ5PV9DOf4zbf43O1X_Bzg1MDkxNzM"
  ) {
    metadata {
      name
    }
    ...on ProviderRevision {
      metadata {
        uid
      }
    }
  }
}

I get:

{
  "data": {
    "kubernetesResource": {
      "metadata": {
        "uid": "3c3d2f11-cf1a-4f49-8e53-88a1110a352c"
      }
    }
  },
  "extensions": {}
}

@negz
Copy link
Member Author

negz commented Jun 10, 2021

I presume the above behaviour is not intended and is still a bug in gqlgen, because this query merges the metadata response into a single object as you'd expect:

query {
  kubernetesResource(
    id: "Xf5rXAL-UHvndETH56dPJgA5XXvndEQ5PV9DOf4zbf43O1X_Bzg1MDkxNzM"
  ) {
    metadata {
      name
    }
    metadata {
      uid
    }
  }
}

@negz
Copy link
Member Author

negz commented Jun 10, 2021

I've raised 99designs/gqlgen#1547 to track this.

@negz negz mentioned this issue Sep 15, 2021
3 tasks
@negz
Copy link
Member Author

negz commented Sep 15, 2021

It's far from ideal, but I wonder whether it's possible to work around the "new" version of this bug (i.e. where inline fragments override less specific queries) by duplicating the information we want inside inline fragments. For example:

query {
  kubernetesResource(
    id: "Xf5rXAL-UHvndETH56dPJgA5XXvndEQ5PV9DOf4zbf43O1X_Bzg1MDkxNzM"
  ) {
    metadata {
      name
    }
    ...on ProviderRevision {
      metadata {
        # We duplicate name here to make sure it's always returned.
        name
        uid
      }
    }
  }
}

@thephred
Copy link
Member

Our use of xgql is through a stitching layer that auto-generates fragments. Not having control of these fragments is why this and the original bug are hard to deal with. At least with the original bug the data was in the payload, just spread among duplicate keys. In this new bug they data is just missing.

@negz
Copy link
Member Author

negz commented Oct 18, 2021

A fix for this has now been merged to gqlgen, but not yet released. Once they get their next release out we should bump it and ship a fixed release of xgql. @thephred will we have any workarounds (e.g. in upbound-graphql) that we'll need to remove?

negz added a commit to negz/xgql that referenced this issue Nov 2, 2021
Normally we'd wait for a release, but I don't know when the next one is due and
master has a fix for upbound#78.

Signed-off-by: Nic Cope <negz@rk0n.org>
@negz negz closed this as completed in #85 Nov 9, 2021
negz added a commit to negz/xgql that referenced this issue Nov 19, 2021
Normally we'd wait for a release, but I don't know when the next one is due and
master has a fix for upbound#78.

Signed-off-by: Nic Cope <negz@rk0n.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-epic-link Needs a link to an epic needs-points-label Needs a story points label needs-project Needs to be added to a project board
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants