This demo repository showcases Grafbase extensions and how they enable easy composition and schema consistency across different types of subgraphs: GraphQL subgraphs (products), databases (PostgreSQL), message queues (NATS), and REST APIs (rest-factories).
This demo includes the following services:
- Products: GraphQL subgraph for product management
- Inventory: GraphQL subgraph for inventory tracking
- Orders: GraphQL subgraph for order processing
- Orders-PG: PostgreSQL database exposed as a GraphQL subgraph via Grafbase PostgreSQL extension
- Sales: NATS message queue exposed as a GraphQL subgraph via Grafbase NATS extension
- REST Factories: REST API exposed as a GraphQL subgraph via Grafbase REST extension
- gRPC Services: A separate demo setup with gRPC-based subgraphs (see grpc/README.md)
Install the Grafbase CLI using one of the following methods:
# Using npx
npx grafbase
# Using curl
curl -fsSL https://grafbase.com/downloads/gateway | bash
# Or see full installation instructions
# https://grafbase.com/docs/gateway/installation-
Start all services with Docker Compose:
docker compose up
-
Run the Grafbase development server:
grafbase dev
-
Access the
grafbase devUI at http://localhost:5000
Simple query to the products subgraph:
query ListProducts {
products {
brand
name
}
}Postgres query:
query OrdersSortedByAmount {
orders(
first: 5
orderBy: [{ totalAmount: DESC }]
) {
edges {
node {
orderId
orderDate
status
totalAmount
customer {
name
email
}
orderItems(first: 2) {
edges {
node {
productName
quantity
unitPrice
}
}
}
}
}
}
}Join from REST (factories) to GraphQL (products) to Postgres (orders):
query RestToGraphQLToPostgres {
factories {
lng
lat
product {
brand
color
latestCustomer {
address
}
}
}
}Post to NATS:
mutation SellProduct {
sellProduct(input: { productId: "converse-1", price: 200 })
}To subscribe to the sales NATS topic defined in the sales subgraph, use the subscription.sh script. It starts a Server Sent Events based GraphQL subscription against localhost:5000/graphql with curl. You should see the event from the mutation above when running this.
/gateway- Gateway configuration for deployment to Fly.io (ignore this in local setups)/grpc- Separate demo with gRPC-based subgraphs/products,/inventory,/orders- GraphQL subgraphs/orders-pg- PostgreSQL backed subgraph with an orders database/sales- NATS message queue subgraph/rest-factories- REST API service
- Grafbase Documentation
- Open source extensions marketplace and repository