- Store GraphQL API URL - https://store-graphql-api-lr5aumczhq-uc.a.run.app/graphql
- Fulfillment GraphQL API URL - https://fulfillment-graphql-api-lr5aumczhq-uc.a.run.app/graphql
- GraphQL <> GraphQL Joins
- Database <> GraphQL Joins
- Database <> Database Joins
An example of joining two GraphQL schemas, a store service and a fulfillment service, with Hasura. Both services were made with GraphQL Code Generator and GraphQL Yoga.
-
Deploy the
fulfillment
andstore
service to any online host. -
In your Hasura Cloud project, add the
FULFILLMENT_SERVICE_URL
andSTORE_SERVICE_URL
enviroment variables. Also add a database named default.
The store service is an example of an ecommerce schema with items and orders containing items
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]!
}
The fulfillment service is an example of a shipping company schema with each fulfillment having an order ID and a status
enum Status {
PACKING
SHIPPED
DELIVERED
}
type Fulfillment {
id: Int!
orderId: Int!
status: Status!
}
type Query {
fulfillment(orderId: Int!): Fulfillment!
fulfillments: [Fulfillment]!
}
Using Hasura GraphQL Joins we can combine the schemas together! From the fulfillment schema orderId
key we join order information from store schema using the order
type ID field. Without any code we have joined two separate services!
{
fulfillment(orderId: 1) {
status
order {
lineItems {
item {
name
}
}
}
}
}
{
"data": {
"fulfillment": {
"status": "PACKING",
"order": {
"lineItems": [
{
"item": {
"name": "Sunglasses"
}
}
]
}
}
}
}