Skip to content

Commit 533dc03

Browse files
authored
[federation] update federation example and enable tests (#1599)
Update Apollo Federation example to match [Federation JVM Spring Example](https://github.com/apollographql/federation-jvm-spring-example) schemas. DGS and GraphQL Java Kickstart also implement the same example schemas. Changes: * Updated base-app/extend-app to match products-subgraph/reviews-subgraph schemas * Added integration tests to both subgraph (start app and run query) * Updated to use new [Rust Router](https://www.apollographql.com/docs/router/). * Added CI that builds the composition, starts the supergraph and runs federated query Related: Resolves #390
1 parent 2f6f7d8 commit 533dc03

File tree

48 files changed

+703
-3419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+703
-3419
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
needs: build-libraries
1717
uses: ./.github/workflows/build-examples.yml
1818

19+
federation-composition:
20+
needs: build-libraries
21+
uses: ./.github/workflows/federation-composition.yml
22+
1923
release-notes:
2024
timeout-minutes: 10
2125
runs-on: ubuntu-latest
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Federation Composition Test
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
federation-composition-test:
8+
timeout-minutes: 30
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: examples/federation
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Java 11
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: 11
21+
distribution: 'zulu'
22+
23+
- name: Set up Gradle cache
24+
uses: gradle/gradle-build-action@v2
25+
26+
- name: Build Subgraphs
27+
working-directory: examples
28+
run: ./gradlew :federation-products-subgraph:build :federation-reviews-subgraph:build
29+
30+
- name: Setup rover CLI
31+
run: |
32+
curl -sSL https://rover.apollo.dev/nix/latest | sh -s -- --elv2-license accept
33+
echo "$HOME/.rover/bin" >> ${GITHUB_PATH}
34+
35+
- name: Compose Supergraph
36+
run: APOLLO_ELV2_LICENSE=accept rover supergraph compose --config supergraph.yaml > supergraph.graphql
37+
38+
- name: Start router
39+
run: docker compose up --build --detach --wait
40+
41+
- name: Federation Tests
42+
run: |
43+
set -x
44+
echo "verify router is up"
45+
curl --verbose http://localhost:8088/health
46+
47+
echo "sending a test query"
48+
curl --request POST \
49+
--verbose \
50+
--header 'content-type: application/json' \
51+
--url http://localhost:3000/ \
52+
--data '{"query":"query($productId: ID!) {\n product(id: $productId) {\n id\n reviews {\n id\n text\n starRating\n }\n name\n description\n }\n}","variables":{"productId":"5"}}' \
53+
> response.json
54+
55+
echo "received GraphQL response"
56+
cat response.json
57+
58+
echo "verifying response"
59+
jq -e '.data.product?.id == "5" and .data.product?.name == "Dragon" and (.data.product?.reviews | length == 2) and (.data.product?.reviews[0]?.text | length > 0)' response.json
60+
- name: Error Logs
61+
if: ${{ failure() }}
62+
run: docker-compose logs
63+
- name: Stop Supergraph
64+
if: ${{ always() }}
65+
run: docker compose down --remove-orphans

.github/workflows/pr-check.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ jobs:
1616
build-examples:
1717
needs: build-libraries
1818
uses: ./.github/workflows/build-examples.yml
19+
20+
federation-composition:
21+
needs: build-libraries
22+
uses: ./.github/workflows/federation-composition.yml

examples/federation/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
supergraph.graphql

examples/federation/README.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,61 @@
11
# Federation Example
22

3-
This example is two Spring applications `base-app` and `extend-app` that use `graphql-kotlin-federation` to generate the schema.
4-
These apps run on different ports (`8080`, `8081`) so they can run simultaniously.
3+
[Apollo Federation](https://www.apollographql.com/docs/federation/) example using GraphQL Kotlin and [Apollo Router](https://www.apollographql.com/docs/router/).
4+
5+
The repository contains two separate projects:
6+
7+
1. `products-subgraph`: A Java GraphQL service providing the federated `Product` type
8+
2. `reviews-subgraph`: A Java GraphQL service that extends the `Product` type with `reviews`
9+
10+
See individual projects READMEs for detailed instructions on how to run them.
11+
12+
## Running example locally
13+
14+
1. Start `products-subgraph` by running the Spring Boot app from the IDE or by running `gradle bootRun` from `products-subgraph` project
15+
2. Start `reviews-subgraph` by running the Spring Boot app from the IDE or `gradle bootRun` from `reviews-subgraph` project
16+
3. Start Federated Router
17+
1. Install [rover CLI](https://www.apollographql.com/docs/rover/getting-started)
18+
2. Start router and compose products schema using [rover dev command](https://www.apollographql.com/docs/rover/commands/dev)
19+
20+
```shell
21+
# start up router and compose products schema
22+
rover dev --name products --url http://localhost:8080/graphql
23+
```
24+
25+
3. In **another** shell run `rover dev` to compose reviews schema
26+
27+
```shell
28+
rover dev --name reviews --url http://localhost:8081/graphql
29+
```
30+
31+
4. Open http://localhost:3000 for the query editor
32+
33+
Example federated query
34+
35+
```graphql
36+
query ExampleQuery {
37+
products {
38+
id
39+
name
40+
description
41+
reviews {
42+
id
43+
text
44+
starRating
45+
}
46+
}
47+
}
48+
```
49+
50+
51+
52+
53+
54+
55+
56+
57+
is two Spring applications `base-app` and `extend-app` that use `graphql-kotlin-federation` to generate the schema.
58+
These apps run on different ports (`8080`, `8081`) so they can run simultaneously.
559

660
The `gateway` is a Node.js app running Apollo Gateway on port `4000` and connects to the two Spring apps.
761
You can make queries against the Spring apps directly or run combined queries from the gateway.
@@ -35,3 +89,41 @@ Once the app has started you can explore the example schema by opening the Playg
3589
### Gateway
3690

3791
See the instructions in the gateway [README](./gateway/README.md)
92+
93+
94+
95+
1. Start `products-subgraph` by running the Spring Boot app from the IDE or by running `./gradlew bootRun` from `products-subgraph` project
96+
2. Start `reviews-subgraph` by running the Spring Boot app from the IDE or `./gradlew bootRun` from `reviews-subgraph` project
97+
3. Start Federated Router
98+
1. Install [rover CLI](https://www.apollographql.com/docs/rover/getting-started)
99+
2. Start router and compose products schema using [rover dev command](https://www.apollographql.com/docs/rover/commands/dev)
100+
101+
```shell
102+
# start up router and compose products schema
103+
rover dev --name products --schema ./products-subgraph/src/main/resources/graphql/schema.graphqls --url http://localhost:8080/graphql
104+
```
105+
106+
3. In **another** shell run `rover dev` to compose reviews schema
107+
108+
```shell
109+
rover dev --name reviews --schema ./reviews-subgraph/src/main/resources/graphql/schema.graphqls --url http://localhost:8080/graphql
110+
```
111+
112+
4. Open http://localhost:3000 for the query editor
113+
114+
Example federated query
115+
116+
```graphql
117+
query ExampleQuery {
118+
products {
119+
id
120+
name
121+
description
122+
reviews {
123+
id
124+
text
125+
starRating
126+
}
127+
}
128+
}
129+
```

examples/federation/base-app/README.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/federation/base-app/build.gradle.kts

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/federation/base-app/src/main/kotlin/com/expediagroup/graphql/examples/federation/base/Application.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/federation/base-app/src/main/kotlin/com/expediagroup/graphql/examples/federation/base/hooks/CustomFederationSchemaGeneratorHooks.kt

Lines changed: 0 additions & 67 deletions
This file was deleted.

examples/federation/base-app/src/main/kotlin/com/expediagroup/graphql/examples/federation/base/queries/NestedQuery.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)