graphql-python / graphene-federation

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

How to preserve "@key" directive in output SDL? #21

Closed tmc closed 1 year ago

tmc commented 1 year ago

I believe newer federation expects @key to be a directive on types that are backed by multiple services.

How do I preserve this in the SDL output?

e.g. output

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

vs

type User {
  id: ID!
  username: String!
}

from example schema:

from graphene import Field, ObjectType, String, ID
from graphene_federation import build_schema, key

@key("id")
class User(ObjectType):
    id = ID(required=True)
    username = String(required=True)
tmc commented 1 year ago

Oh it it something like this:

if __name__ == "__main__":
    from graphql import graphql_sync
    result = graphql_sync(schema.graphql_schema, '{ _service { sdl } }')
    print(result.data["_service"]["sdl"].strip())
erikwrede commented 1 year ago

Yes, the schema printer in GQL-Core won't include these directives by design. You can only get the full federated schema using the introspection query. We should add this to the docs soon 😊