This template can be used to quickly create an Apollo Federation subgraph with Strawberry GraphQL.
To get started, install rover and then run the following commands:
rover template use -t subgraph-python-strawberry-fastapi- A basic, Apollo Federation subgraph with simple examples for queries, entities, and mutations.
- Example tests in the
testsdirectory. - GitHub Actions workflows which will:
- Run
pyteston every push. - Check the schema against Apollo Studio on every push.
- Publish the subgraph to Apollo Studio on every push to the
mainbranch.
- Run
You can now run the following commands to get started:
python -m venv .virtualenv
source .virtualenv/bin/activate
pip install -r requirements.txt -r requirements-dev.txtTo run the server, run:
uvicorn main:app --reloadThe GitHub actions for this template are configured to publish the subgraph to Apollo Studio. But they are disabled by default. To enable them, you'll need to add the following secrets to your repository:
APOLLO_KEY: An Apollo Studio API key for the supergraph to enable schema checks and publishing of the subgraph.APOLLO_GRAPH_REF: The name of the graph in Apollo Studio to publish the subgraph to. This should be in the formatgraph-name@variant-name.PRODUCTION_URL: The URL of the deployed subgraph that the supergraph gateway will route to.SUBGRAPH_NAME: The name of the subgraph in Apollo Studio.
And remove the if: false from the publish step in the publish-schema.yml
and check-schema.yml workflows.
Typically, you do not want to allow the public to query your subgraph. To configure the subgraph to only accept requests from your Router, send the Router-Authorization header from your Cloud router and set the ROUTER_SECRET environment variable wherever you deploy this to.