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

Federation entity union is empty during schema introspection #700

Closed
ggrise opened this issue Nov 11, 2021 · 7 comments
Closed

Federation entity union is empty during schema introspection #700

ggrise opened this issue Nov 11, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@ggrise
Copy link

ggrise commented Nov 11, 2021

Expected Behavior

union _Entity = ... list of entities..

Actual Behavior

union _Entity = empty

Steps to Reproduce the Problem

Create a federated entity and do a schema introspection, union _Entity remain empty.

I believe the bug was introduced in v2.10.3

Specifications

  • Version: v2.10.3
  • Platform:
  • Subsystem:
@ggrise ggrise added the bug Something isn't working label Nov 11, 2021
@sunli829
Copy link
Collaborator

Can you give an example to reproduce this problem? 🙂

@ggrise
Copy link
Author

ggrise commented Nov 12, 2021

Yes, sorry for not giving more details:

If we run /async-graphql/examples/federation/federation-reviews and execute an introspection query on it

query IntrospectionQuery { __schema { types { name,kind,possibleTypes { name }  }}}

We should expect:

{
  "kind": "UNION",
  "name": "_Entity",
  "possibleTypes": [
    {
      "name": "Product"
    },
    {
      "name": "User"
    }
  ]
},

But we get the following instead

{
  "kind": "UNION",
  "name": "_Entity",
  "possibleTypes": []
},

thanks!

@sunli829
Copy link
Collaborator

Because this service itself does not contain any entities.

You should do it like this:

https://github.com/async-graphql/examples/blob/8641a72c8ccb78e924e2550cd1fbfa2e62319174/federation/README.md

@ggrise
Copy link
Author

ggrise commented Nov 12, 2021

You can repeat it with federation-products example:

full details:

Run the federation product service (no need for a gateway)

$ cd examples/federation/federation-products
$ cargo run 

Curl the service directly with an introspection query:

$ curl 'http://localhost:4002/graphql' --data-raw '{"operationName":"IntrospectionQuery","variables":{},"query":"query IntrospectionQuery { __schema { types { name,kind,possibleTypes { name }  }}}"}' |  jq  '.data.__schema.types[]|select(.name == "_Entity")'
{
  "name": "_Entity",
  "kind": "UNION",
  "possibleTypes": []
}

Notice the possibleTypes should be set to Product since it's a federated entity in federation-products

Since the bug was introduced in v2.10.3, if you checkout v2.10.2 and run federation-products again:

$ git checkout v2.10.2
$ cd examples/federation-products
$ cargo run

You get the correct answer for possibleTypes

$ curl 'http://localhost:4002/graphql' --data-raw '{"operationName":"IntrospectionQuery","variables":{},"query":"query IntrospectionQuery { __schema { types { name,kind,possibleTypes { name }  }}}"}' |  jq  '.data.__schema.types[]|select(.name == "_Entity")'
{
  "kind": "UNION",
  "name": "_Entity",
  "possibleTypes": [
    {
      "name": "Product"
    }
  ]
}

I believe the bug was introduced here:

} else if let TypeDetail::Named(registry::MetaType::Union { union_values, .. }) =

union_values is used to list the possibleTypes, but unfortunately, we don't add the types into union_values when we defined _Entity.

union_values: Default::default(),

I can make a PR if you like.

@Miaxos
Copy link
Member

Miaxos commented Nov 12, 2021

Oops, it seems I forgot something, it's my commit: a3b7777

@sunli829 sunli829 pinned this issue Nov 13, 2021
@sunli829
Copy link
Collaborator

I'm working on it.

@sunli829
Copy link
Collaborator

Fixed in 3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants