Combine Multiple GraphQL APIs using Hasura's GraphQL Joins
- Remote Schema to Remote Schema (RS-to-RS) Joins
- Database to Database (DB-to-DB) Joins
- Database to Remote Schema (DB-to RS) Joins
- Remote Schema to Database (RS-to-DB) Joins
How do RS-to-RS Joins work?
E-Commerce Example with Hasura
Store Service
type Item {
id: Int!
name: String!
price: Float!
}
type LineItem {
quantity: Int!
itemId: Int!
item: Item
}
type Order {
id: Int!
lineItems: [LineItem!]!
}
type Query {
item(id: Int!): Item
items: [Item!]!
order(id: Int!): Order
orders: [Order]!
}
Fulfillment Service
enum Status {
PACKING
SHIPPED
DELIVERED
}
type Fulfillment {
id: Int!
orderId: Int!
status: Status!
}
type Query {
fulfillment(orderId: Int!): Fulfillment!
fulfillments: [Fulfillment]!
}
Joining the Remote Schemas
{
fulfillment(orderId: 1) {
status
order {
lineItems {
item {
name
}
}
}
}
}
{
"data": {
"fulfillment": {
"status": "PACKING",
"order": {
"lineItems": [
{
"item": {
"name": "Sunglasses"
}
}
]
}
}
}
}
Related reading