Apollo GraphQL Federation demo in multiple languages.
This project is used to demo joing Graph layers from various languages and libraries.
graph TD
Client(Client)--request-->Gateway(Data Graph Gateway - Node)
Gateway-->Customers(Customers - Node)
Customers-->Gateway
Gateway-->Orders(Orders - Node)
Orders-->Gateway
Gateway-->Products(Products - Node)
Products-->Gateway
Gateway-->Reviews(Reviews - Ruby)
Reviews-->Gateway
Gateway--response-->Client
- Make sure you are using the latest Node LTS
nvm use
- Install Dependencies
yarn install
- Start Federated Services
yarn start-services
- Start Gateway (Data Graph)
yarn start-gateway
- Start Apollo Client Next.js App
yarn start-client
- Visit
http://localhost:4000
in browser to launch GraphQL Playground (Graphiql)
tip: if you need to kill any tcp ports lsof -ti tcp:<PORT> | xargs kill
or sudo kill -9 $(lsof -i :<PORT> -t)
Refer to DOCS
inside Graphiql for more information on queries and muations.
allOrders
: Retrieve all orders.
query {
allOrders {
id
financialStatus
fulfillmentStatus
customer {
id
firstName
lastName
email
}
}
}
customerByEmail
: Retrieves customer information by email including all orders placed by customer.
query {
customerByEmail(email: "janedoe@example.com") {
firstName
lastName
email
orders {
id
financialStatus
fulfillmentStatus
}
}
}
deleteOrder
: Deletes one order.
mutation {
deleteOrder(id: "order-2") {
id
financialStatus
fulfillmentStatus
customer {
id
firstName
lastName
email
}
}
}
Apollo servers features automatic persisted queries. Apollo Client will make a GET request utalizing a SHA256 hash to reference a query. If that query is not in memory on Apollo Server, it will respond with "code": "PERSISTED_QUERY_NOT_FOUND"
, subsequently Apollo Client will then make a standard GraphQL POST request to Apollo Server with the same hash so that Apollo Server can save the query in memory.
Redis, Memcached, or any standard key value store can be used to persist the data on your Apollo Server. By default Apollo Server will utalize in-memory cache.
Advatages include improved network performance by utalizing HTTP caching to reduce query string size on GET requests.
Sample query string parameters sent on GET request
{
"persistedQuery": {
"version":1,"sha256Hash":"3652ff3ed3e55b94ab31a26a3c65221f30df1432e80d6ebbd3cabf730eac3b94"
}
}
Apollo Graph Manager (formerly Apollo Engine) is a cloud service that helps you manage, validate, and secure your organization's data graph.
graph LR
A(Data Graph Gateway)-->B(Apollo Graph Manager)
B-->A
note: use npx
if not installed globally, npm install -g apollo
- Run all services
yarn start-services
and gatewayyarn start-gateway
- Login or create an account Apollo Data Graph Manager.
- Update
ENGINE_API_KEY
in.env
file. - Push schema to Data Graph Manager from root
apollo service:push --endpoint=http://localhost:4000
- Register each federated services
apollo service:push --serviceName="customers" --serviceURL="http://customers-graphql.svc.cluster.local:4001/" --endpoint="http://localhost:4001/"
- List all federated services:
apollo service:list
TODO: connect to CI/CD process