graphql-python / graphene-federation

Federation implementation for Graphene.
MIT License
40 stars 10 forks source link

the key is not showing in the schema after applying @key decorator #11

Closed sahilrl closed 1 year ago

sahilrl commented 1 year ago
@key('id')
class CountryType(graphene_django.DjangoObjectType):

    def __resolve_reference(self, info, **kwargs):
        return 1

    class Meta:
        model = Country
        interfaces = (relay.Node,)

This is the schema being created


type Query {
    country: [CountryType]
  _entities(representations: [_Any!]!): [_Entity]!
  _service: _Service!
}

....

type CountryType implements Node {
  """The ID of the object"""
  id: ID!
  name: String!
  officialStateName: String!
  alpha2Code: String!
  alpha3Code: String!
  unCode: Int!
  region: CoreCountryRegionChoices!
}

union _Entity = CountryType
erikwrede commented 1 year ago

Thanks for the report 🙂 How did you obtain the SDL? If you used the normal introspection query, please keep in mind that Schema Directives aren't included in the introspection result. To introspect a federated schema including the federated directives, you can use this:

    query = """
    query {
        _service {
            sdl
        }
    }
    """
    result = graphql_sync(schema.graphql_schema, query)

See: https://github.com/graphql-python/graphene-federation/blob/main/graphene_federation/tests/test_key.py

sahilrl commented 1 year ago

Thankyou @erikwrede The above method works to obtain the SDL with federated directives included.