Skip to content

Commit 1079a11

Browse files
committed
Apollo Router using Fed 1 supergraph schema
Signed-off-by: Phil Prasek <prasek@gmail.com>
1 parent a7b414a commit 1079a11

19 files changed

+553
-87
lines changed

.github/workflows/main-router.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI-router
2+
on:
3+
pull_request:
4+
branches: [ main ]
5+
schedule:
6+
- cron: '30 7 * * *'
7+
workflow_dispatch:
8+
9+
jobs:
10+
ci-docker-local:
11+
name: CI
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: checkout
15+
uses: actions/checkout@v2
16+
-
17+
name: install rover
18+
run: |
19+
echo ---------------------------------------------------------------
20+
echo rover - installing ...
21+
echo ---------------------------------------------------------------
22+
curl -sSL https://rover.apollo.dev/nix/latest | sh
23+
echo "$HOME/.rover/bin" >> ${GITHUB_PATH}
24+
-
25+
name: update docker-compose
26+
run: |
27+
which docker-compose && exit 0 || true
28+
echo ---------------------------------------------------------------
29+
echo docker-compose - installing ...
30+
echo ---------------------------------------------------------------
31+
BIN_DIR=$HOME/.docker-compose/bin
32+
FILE=$BIN_DIR/docker-compose
33+
mkdir -p $BIN_DIR
34+
set -x
35+
curl -L --fail https://github.com/docker/compose/releases/download/1.29.1/docker-compose-`uname -s`-`uname -m` -o $FILE
36+
chmod +x $FILE
37+
echo "downloaded $($FILE --version)"
38+
echo "$BIN_DIR" >> ${GITHUB_PATH}
39+
set +x
40+
echo ---------------------------------------------------------------
41+
-
42+
name: check tools
43+
run: |
44+
echo ---------------------------------------------------------------
45+
( set -x; which rover )
46+
echo "$(rover --version)"
47+
echo ---------------------------------------------------------------
48+
( set -x; which docker-compose )
49+
echo "$(docker-compose --version)"
50+
echo ---------------------------------------------------------------
51+
- name: make supergraph
52+
run: |
53+
make supergraph
54+
cat supergraph.graphql
55+
- name: docker-compose build
56+
run: |
57+
( set -x; docker-compose -f docker-compose.router.yml build --no-cache --pull --parallel --progress plain )
58+
- name: docker-compose up -d
59+
run: |
60+
( set -x; docker-compose -f docker-compose.router.yml up -d )
61+
sleep 3
62+
docker-compose -f docker-compose.router.yml logs
63+
- name: smoke test
64+
run: .scripts/smoke.sh 4000
65+
- name: docker-compose down
66+
run: docker-compose -f docker-compose.router.yml down

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ lerna-debug.log*
99
graph-api.env
1010
docker.secrets
1111

12+
router/router
13+
1214
# Diagnostic reports (https://nodejs.org/api/report.html)
1315
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1416

Makefile

+27-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ default: demo
44
.PHONY: ci
55
ci: supergraph docker-build-force docker-up smoke docker-down
66

7+
.PHONY: ci-router
8+
ci-router: supergraph docker-build-force docker-up-local-router smoke docker-down-router
9+
710
.PHONY: demo
811
demo: supergraph docker-up smoke docker-down
912

@@ -20,7 +23,7 @@ demo-serverless: supergraph-serverless docker-up-serverless smoke docker-down-se
2023
docker-up:
2124
docker-compose up -d
2225
@sleep 2
23-
@docker logs router
26+
@docker logs apollo-gateway
2427

2528
.PHONY: docker-build
2629
docker-build:
@@ -30,11 +33,24 @@ docker-build:
3033
docker-build-force:
3134
docker-compose build --no-cache --pull --parallel --progress plain
3235

36+
.PHONY: docker-build-router
37+
docker-build-router:
38+
@docker build -t supergraph-demo_apollo-router router/. --no-cache
39+
3340
.PHONY: docker-up-managed
3441
docker-up-managed:
3542
docker-compose -f docker-compose.managed.yml up -d
3643
@sleep 2
37-
@docker logs router
44+
@docker logs apollo-gateway
45+
46+
.PHONY: demo-local-router
47+
demo-local-router: supergraph docker-up-local-router smoke docker-down-router
48+
49+
.PHONY: docker-up-local-router
50+
docker-up-local-router:
51+
docker-compose -f docker-compose.router.yml up -d
52+
@sleep 2
53+
@docker logs apollo-router
3854

3955
.PHONY: query
4056
query:
@@ -46,7 +62,11 @@ smoke:
4662

4763
.PHONY: docker-down
4864
docker-down:
49-
docker-compose down
65+
docker-compose down --remove-orphans
66+
67+
.PHONY: docker-down-router
68+
docker-down-router:
69+
docker-compose -f docker-compose.router.yml down --remove-orphans
5070

5171
.PHONY: supergraph
5272
supergraph: config compose
@@ -162,6 +182,10 @@ act: act-ci-local
162182
act-ci-local:
163183
act -P $(ubuntu-latest) -W .github/workflows/main.yml --detect-event
164184

185+
.PHONY: act-ci-local-router
186+
act-ci-local-router:
187+
act -P $(ubuntu-latest) -W .github/workflows/main-router.yml --detect-event
188+
165189
.PHONY: act-ci-managed
166190
act-ci-managed:
167191
act -P $(ubuntu-latest) -W .github/workflows/managed.yml --secret-file graph-api.env --detect-event -j ci-docker-managed

README.md

+72-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Contents:
2525
* [Deployment Examples](#deployment-examples)
2626
* [Kubernetes with Supergraph ConfigMap](#kubernetes-with-supergraph-configmap)
2727
* [Serverless](#serverless)
28+
* [Apollo Router](#apollo-router)
29+
* [Learn More](#learn-more)
30+
31+
See also:
32+
- [apollographql/supergraph-demo-fed2](https://github.com/apollographql/supergraph-demo-fed2/blob/main/README.md)
33+
- [apollographql/supergraph-demo-k8s-graph-ops](https://github.com/apollographql/supergraph-demo-k8s-graph-ops)
2834

2935
## Welcome
3036

@@ -96,7 +102,7 @@ and then runs:
96102
```
97103
docker-compose up -d
98104
99-
Creating router ... done
105+
Creating apollo-gateway ... done
100106
Creating inventory ... done
101107
Creating users ... done
102108
Creating products ... done
@@ -258,7 +264,7 @@ service:
258264
* Docker compose file: [docker-compose.otel-collector.yml](docker-compose.otel-collector.yml)
259265
* Helper library: [supergraph-demo-opentelemetry](https://github.com/prasek/supergraph-demo-opentelemetry)
260266
* See usage in:
261-
* [router/router.js](router/router.js)
267+
* [gateway/gateway.js](gateway/gateway.js)
262268
* [subgraphs/products/products.js](subgraphs/products/products.js)
263269

264270
## Apollo Studio
@@ -339,16 +345,16 @@ Viewing the `Federated` graph in Apollo Studio we can see the supergraph and the
339345

340346
#### Run the Graph Router and Subgraph Containers
341347

342-
The graph-router and subgraph services will be started by `make demo-managed` next.
348+
The graph router and subgraph services will be started by `make demo-managed` next.
343349

344350
using `docker-compose.managed.yml`:
345351

346352
```yaml
347353
version: '3'
348354
services:
349-
router:
350-
container_name: router
351-
build: ./router
355+
apollo-gateway:
356+
container_name: apollo-gateway
357+
build: ./gateway
352358
environment:
353359
- APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT=https://uplink.api.apollographql.com/
354360
env_file: # created with: make graph-api-env
@@ -375,7 +381,7 @@ which shows:
375381
```
376382
docker-compose -f docker-compose.managed.yml up -d
377383
Creating network "supergraph-demo_default" with the default driver
378-
Creating graph-router ... done
384+
Creating apollo-gateway ... done
379385
380386
Starting Apollo Gateway in managed mode ...
381387
Apollo usage reporting starting! See your graph at https://studio.apollographql.com/graph/supergraph-router@dev/
@@ -408,7 +414,7 @@ Apollo Schema Checks help ensure subgraph changes don't break the federated grap
408414

409415
#### The Graph Router will Update In Place
410416

411-
With Managed Federation you can leave graph-router running and it will
417+
With Managed Federation you can leave the graph router running and it will
412418
update automatically when subgraph changes are published and they successfully
413419
compose and pass all schema checks in Apollo Studio:
414420

@@ -870,6 +876,64 @@ Removing serverless ... done
870876
Removing network supergraph-demo_default
871877
```
872878

879+
## Apollo Router
880+
881+
[The Apollo Router](https://www.apollographql.com/blog/announcement/backend/apollo-router-our-graphql-federation-runtime-in-rust) is our next-generation GraphQL Federation runtime written in Rust, and it is fast.
882+
883+
As a Graph Router, the Apollo Router plays the same role as the Apollo Gateway. The same subgraph schemas and composed supergraph schema can be used in both the Router and the Gateway.
884+
885+
This demo shows using the Apollo Router with a Federation 1 supergraph schema, composed using the Fed 1 `rover supergraph compose` command. To see the Router working with Federation 2 composition, checkout the Apollo Router section of [apollographql/supergraph-demo-fed2](https://github.com/apollographql/supergraph-demo-fed2/blob/main/README.md#apollo-router).
886+
887+
[Early benchmarks](https://www.apollographql.com/blog/announcement/backend/apollo-router-our-graphql-federation-runtime-in-rust) show that the Router adds less than 10ms of latency to each operation, and it can process 8x the load of the JavaScript Apollo Gateway.
888+
889+
To get started with the Router:
890+
891+
```
892+
make demo-local-router
893+
```
894+
895+
this uses a simple [docker-compose.router.yml](docker-compose.router.yml) file:
896+
```yaml
897+
version: '3'
898+
services:
899+
apollo-router:
900+
container_name: apollo-router
901+
build: ./router
902+
volumes:
903+
- ./supergraph.graphql:/etc/config/supergraph.graphql
904+
- ./router/configuration.yaml:/etc/config/configuration.yaml
905+
ports:
906+
- "4000:4000"
907+
products:
908+
container_name: products
909+
build: ./subgraphs/products
910+
inventory:
911+
container_name: inventory
912+
build: ./subgraphs/inventory
913+
users:
914+
container_name: users
915+
build: ./subgraphs/users
916+
```
917+
918+
which uses the following [Dockerfile](router/Dockerfile)
919+
```
920+
from ubuntu
921+
922+
WORKDIR /usr/src/app
923+
RUN apt-get update && apt-get install -y \
924+
libssl-dev \
925+
curl \
926+
jq
927+
928+
COPY install.sh .
929+
COPY run.sh .
930+
RUN ./install.sh
931+
932+
CMD [ "/usr/src/app/run.sh" ]
933+
```
934+
935+
see [./router](router) for more details.
936+
873937
## Learn More
874938

875939
Apollo tools and services help you develop, maintain, operate, and scale your data graph.

docker-compose.managed.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
3-
router:
4-
container_name: router
5-
build: ./router
3+
apollo-gateway:
4+
container_name: apollo-gateway
5+
build: ./gateway
66
env_file: # create with make graph-api-env
77
- graph-api.env
88
ports:

docker-compose.otel-collector.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
3-
router:
4-
container_name: router
5-
build: ./router
3+
apollo-gateway:
4+
container_name: apollo-gateway
5+
build: ./gateway
66
environment:
77
- APOLLO_SCHEMA_CONFIG_EMBEDDED=true
88
- APOLLO_OTEL_EXPORTER_TYPE=collector

docker-compose.otel-zipkin.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
3-
router:
4-
container_name: router
5-
build: ./router
3+
apollo-gateway:
4+
container_name: apollo-gateway
5+
build: ./gateway
66
environment:
77
- APOLLO_SCHEMA_CONFIG_EMBEDDED=true
88
- APOLLO_OTEL_EXPORTER_TYPE=zipkin

docker-compose.router.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3'
2+
services:
3+
apollo-router:
4+
container_name: apollo-router
5+
build: ./router
6+
volumes:
7+
- ./supergraph.graphql:/etc/config/supergraph.graphql
8+
- ./router/configuration.yaml:/etc/config/configuration.yaml
9+
ports:
10+
- "4000:4000"
11+
products:
12+
container_name: products
13+
build: ./subgraphs/products
14+
inventory:
15+
container_name: inventory
16+
build: ./subgraphs/inventory
17+
users:
18+
container_name: users
19+
build: ./subgraphs/users

docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
3-
router:
4-
container_name: router
5-
build: ./router
3+
apollo-gateway:
4+
container_name: apollo-gateway
5+
build: ./gateway
66
environment:
77
- APOLLO_SCHEMA_CONFIG_EMBEDDED=true
88
volumes:

gateway/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from node:16-alpine
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package.json .
6+
7+
RUN npm install
8+
9+
COPY gateway.js .
10+
11+
CMD [ "node", "gateway.js" ]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)