Micro‑Federation
Use micro‑federation to compose multiple Axolotl modules in a single project or monorepo (or via npm packages). Individual schemas are merged into a supergraph that your server uses at runtime.
You can also run the project examples/yoga-federated
to watch how
micro federation works!
To enable it, configure axolotl.json
like:
axolotl.json
{
"schema": "schema.graphql",
"models": "src/models.ts",
"federation":[
{
"schema":"src/todos/schema.graphql",
"models":"src/todos/models.ts",
},
{
"schema":"src/users/schema.graphql",
"models":"src/users/models.ts",
}
]
}
schema
/models
point to the supergraph schema and its generated models.
Federation flow:
- Generate models for each entry in
federation
. - Merge those schemas into the supergraph saved at
schema
. - Generate models for the supergraph.
To run federated axolotls - each of folders, users
and todos
in our case has
to provide their own resolvers.ts
files based on local models and Axolotl
.
Then inside the main resolvers.ts
file we need to merge the subgraph
resolvers:
src/resolvers.ts
import { mergeAxolotls } from '@aexol/axolotl-core';
import usersResolvers from '@/src/users/resolvers.js';
import todosResolvers from '@/src/todos/resolvers.js';
export default mergeAxolotls(usersResolvers, todosResolvers);
Use the merged resolvers as the adapter input, just like a single‑schema setup.