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

Gateway does not trigger correct resolvers when subgraphs extend and reuse shared types #58

Open
abc-moviestarplanet opened this issue Feb 1, 2023 · 5 comments

Comments

@abc-moviestarplanet
Copy link

abc-moviestarplanet commented Feb 1, 2023

Given the following 2 graphql subgraphs:

Subgraph 1:

  extend type Query {
    users: PageOfUser
  }

  type PageOfUser {
    nodes: [User]
  }

  type User @key(fields: "id") {
    id: ID!
    name: String
  }

Subgraph 2:

  extend type User @key(fields: "id") {
    id: ID! @external
    friends: PageOfUser # <-- this is problematic
  }

  type PageOfUser {
    nodes: [User]
  }

Subgraph 2 has a resolver for friends which always returns some data.

If I run the following query against the Gateway:

query {
  users {
    nodes {
      id
      friends {
        nodes {
          id 
        }
      }
    }
  }
}

The response is:

{
  "data": {
    "users": {
      "nodes": [
        {
          "id": "0",
          "friends": null // should not be null
        },
        {
          "id": "1",
          "friends": null // should not be null
        }
      ]
    }
  }
}

And the friends resolver never triggers.

I can get the data for friends correctly if I manually query subgraph 2 directly like this:

query {
  _entities(representations: [{ __typename:"User", id: 1 }]) {
    ...on User {
      id
      friends {
        nodes {
          id
        }
      }
    }
  }
}

So from what I can understand, the Gateway is not requesting the "friends" data from Subgraph 2.

Now if in Subgraph 2 I rename the type PageOfUser to PageOfFriends (a name that is different from that defined in Subgraph 1) then it works fine through the Gateway.

According to this https://www.apollographql.com/docs/federation/v1/value-types/, it is fine for the subgraphs to define the same types multiple times, as long as they are exactly identical.

Is this a bug or a misuse of federation?

Sample to reproduce:

https://github.com/abc-moviestarplanet/GatewayResolverIssue/tree/main

@mcollina
Copy link
Contributor

mcollina commented Feb 1, 2023

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@abc-moviestarplanet
Copy link
Author

Here is a repository with steps to reproduce: https://github.com/abc-moviestarplanet/GatewayResolverIssue/tree/main

@mcollina
Copy link
Contributor

mcollina commented Feb 2, 2023

@marco-ippolito could you take a look?

@marco-ippolito
Copy link
Contributor

probably related to #22

@Drilmo
Copy link

Drilmo commented Apr 5, 2024

Hi, have you find why it doesn't work ? i think my issue is the same 😭 #114
It's blocker for me....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants