graphql-python / graphene-federation

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

Generate schema with federation directives #16

Closed Meemaw closed 1 year ago

Meemaw commented 1 year ago

We are generating GraphQL schema using via https://github.com/graphql-python/graphene-django , e.g poetry run python manage.py graphql_schema --out schema.graphql.

This command is not aware of the federation annotations so can't be used. Is there any known workaround for this?

erikwrede commented 1 year ago

Hey there, in order to get the correct schema, you need to run an introspection query:

query {
  _service {
    sdl
  }
}

This will add all of the schema directives to your federated schema. The standard graphql schema printer does not have that functionality.

A workaround would be to create a custom manage.py which adds a method that runs the following code

from graphene_federation import build_schema
schema = build_schema(query=Query)
result = schema.execute("""
query {
  _service {
    sdl
  }
}""")

# save schema to file or output

Please let me know if that helps or if you need any further assistance. 😊

Meemaw commented 1 year ago

Hey, I was considering this, but for some reason felt its a bit hacky. It will work though. Thanks!