A development server for Apollo Federation that allows you to run and test GraphQL subgraphs locally. This tool helps you develop and test federated GraphQL schemas by providing mock data and automatic schema composition.
- Run multiple GraphQL subgraphs locally
- Automatic mock data generation for GraphQL types
- Customizable mock data using directives
- Real-time schema watching and reloading
- Supergraph composition with Apollo Federation
- Fetch new GraphQL schemas from Apollo Studio
Download the latest release from the GitHub releases page or build from source.
The tool provides two main commands: serve and fetch.
Run a local development server with multiple subgraphs, suitable for exposing to Apollo Router:
graphql-federation-dev serve --schemas subgraph1=./schemas/subgraph1.graphql --schemas subgraph2=./schemas/subgraph2.graphql --output ./supergraph.graphqlOnce the server is running, it will automatically compose the supergraph schema from the provided subgraphs into the indicated file (supergraph.graphql). You can then launch Apollo Router against these mock subgraphs:
router -c router-config.yaml -s supergraph.graphqlCreate a new federated GraphQL project with multiple subgraphs:
graphql-federation-dev new ./my-project --subgraph users --subgraph productsThis will create a new project directory with basic schema files for each specified subgraph.
Generate a new GraphQL schema from an Apollo Studio proposal:
graphql-federation-dev fetch --proposal-number 123 ./output-directory| Option | Description | Default |
|---|---|---|
--pretty-traces |
Enable pretty-printed traces for debugging | false |
| Option | Description | Default |
|---|---|---|
--schemas, -s |
Schema files in the format subgraph=file_name.graphql |
Required |
--output, -o |
Output path for the composed supergraph schema | Required |
--port |
Port to run the server on | 8080 |
| Option | Description | Default |
|---|---|---|
--subgraph, -s |
Names of subgraphs to create | Required |
path |
Path to the folder where the project will be created | Required |
| Option | Description | Default |
|---|---|---|
--proposal-number, -p |
Apollo Studio proposal number | Required |
path |
Path to the folder where the schema will be created | Required |
The server generates mock data for your GraphQL types. You can customize this data using the following directives:
Generates random text with a specified number of words.
type User {
bio: String @words(min: 10, max: 20)
}Selects a random value from a provided list.
type Product {
category: String @select(from: ["Electronics", "Clothing", "Books", "Home"])
}Specifies the number of items in a list.
type User {
tags: [String!]! @count(min: 2, max: 5)
}type Query {
user: User
products: [Product!]! @count(min: 3, max: 10)
}
type User {
id: ID!
username: String @words(min: 1, max: 2)
name: String @select(from: ["John Doe", "Jane Smith", "Alex Johnson"])
bio: String @words(min: 10, max: 30)
favoriteProducts: [Product!]! @count(min: 1, max: 3)
}
type Product {
id: ID!
name: String @words(min: 2, max: 4)
category: String @select(from: ["Electronics", "Clothing", "Books"])
price: Float
inStock: Boolean
}This server supports Apollo Federation directives and features, allowing you to develop and test federated GraphQL schemas locally.
type User @key(fields: "id") {
id: ID!
username: String
}
type Product @key(fields: "id") {
id: ID!
name: String
}To build and run the project locally:
cargo build
cargo run -- --schemas example=./example.graphql --output ./supergraph.graphqlMIT