This is a combination of official starter Turborepo, NextJs and Apollo Supergraph (Federation) demo.
This turborepo uses pnpm as a packages manager. It is not only turbo charged with turbo but it also has integrated supergraph subgraph demo of Apollo.
Althought it is not a complete example with nice file names and integrated rover etc, I hope this could give you an insight to start building your own super Turbo Federated Graphql apps.
It includes the following packages/apps:
docs
: a Next.js appweb
: another Next.js app uses apollo gateway that combines all the subgraphs and serve them in one supergraphaccounts
: another Next.js app uses apollo subgraph to create subgraphs for accountsinventory
: another Next.js app uses apollo subgraph to create subgraphs for inventoryproducts
: another Next.js app uses apollo subgraph to create subgraphs for productsreviews
: another Next.js app uses apollo subgraph to create subgraphs for reviewsui
: a stub React component library shared by bothweb
anddocs
applicationsconfig
:eslint
configurations (includeseslint-config-next
andeslint-config-prettier
)tsconfig
:tsconfig.json
s used throughout the monorepo
Each package/app is 100% TypeScript.
This turborepo has some additional tools already setup for you:
- TypeScript for static type checking
- ESLint for code linting
- Jest test runner for all things JavaScript
- Prettier for code formatting
This repository is using (PNPM) package manager to manage your monorepo .
create .env.local file in apps/web directory insert the variables below
ACCOUNTS_GRAPHQL_ENDPOINT=http://localhost:3002/api/graphql
REVIEWS_GRAPHQL_ENDPOINT=http://localhost:3005/api/graphql
INVENTORY_GRAPHQL_ENDPOINT=http://localhost:3003/api/graphql
PRODUCTS_GRAPHQL_ENDPOINT=http://localhost:3004/api/graphql
To build all apps and packages, run the following command:
cd turbo-federation
pnpm run build
To develop all apps and packages, run the following command:
cd turbo-federation
pnpm run dev
To test everything is running perfectly try this query locally on localhost:3000/api/graphql or checkout the production gateway on Apollo Studio: Turbo Federation Demo
query Query {
topProducts(first: 5) {
inStock
name
price
reviews {
author {
name
username
}
body
}
shippingEstimate
weight
}
me {
name
username
reviews {
product {
name
}
body
}
}
}
Turborepo can use a technique known as Remote Caching (Beta) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
By default, Turborepo will cache locally. To enable Remote Caching (Beta) you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:
cd turbo-federation
pnpx turbo login
This will authenticate the Turborepo CLI with your Vercel account.
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your turborepo:
pnpx turbo link
Learn more about the power of Turborepo: