This project demonstrates a federated GraphQL setup composed of two FastAPI microservices and an Apollo Gateway. Each service can be run individually or all together using Docker.
Use the package manager pip to install requirements.
Go to one of the microservice folders and run:
pip install -r requirements.txtOpen the user_service folder in your terminal and run:
uvicorn app:app --port 8000 --reloadOpen the task_service folder in your terminal and run:
uvicorn app:app --port 8800 --reloadOpen the gateway folder in your terminal and isntall npm dependencies:
npm installnpm run-script devFederation of the two microservices will be available on port 8080
Access: http://localhost:8080
To start all services at once use docker-compose:
docker-compose build
docker-compose upThe gateway will be available on http://localhost:8080
In the microservice folder run:
strawberry export-schema schema.schema > schema/schema.graphqlmutation {
createUser(
cpf: "12345678900"
email: "fabio@example.com"
name: "Fábio Vitor"
) {
id
name
email
cpf
}
}mutation {
addCategory(categoryName: "Tecnologia") {
__typename
... on Category {
id
categoryName
}
... on CategoryExists {
message
}
}
}mutation {
addTask(
categoryName: "Tecnologia"
taskName: "Estudar Federation"
userId: 1
) {
__typename
... on Task {
id
taskName
userId
category {
id
categoryName
}
}
... on TaskExists {
message
}
}
}query {
users(cpf: "12345678900") {
id
name
email
tasks {
id
taskName
category {
id
categoryName
}
}
}
}