Micro federation

Micro Federation

You can use micro federation feature in axolotl. Micro federation means all the modules are located within one project or one monorepo or are distributed as npm packages. Those axolotl projects are merged to the supergraph later.

You can also run the project examples/yoga-federated to watch how micro federation works!

To use micro federation you need to create config for your project containing this kind of content:

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",
        }
    ]
}

Inside this config main field schema and models specify paths for supergraph schema and its models. Here is how the federation process works:

  1. Take all the schemas from federation array and generate models file for each
  2. Create supergraph schema from all the federation schemas.
  3. Create models for 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 wee need to merge those 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);

then you can use those resolvers as normal resolvers result.