Generate schema with federation directives
Meemaw opened this issue · comments
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?
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. 😊
Hey, I was considering this, but for some reason felt its a bit hacky. It will work though. Thanks!