Skip to content

Commit 0b9a83c

Browse files
authored
fixing router health check endpoint (#233)
1 parent f781668 commit 0b9a83c

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
- ./supergraph.graphql:/dist/config/supergraph.graphql
77
ports:
88
- 4000:4000
9+
- 8088:8088
910
command: -c config/router.yaml -s config/supergraph.graphql
1011
inventory:
1112
image: apollo-federation-implementations/inventory

router.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
cors:
2+
# allow_credentials: true
3+
allow_any_origin: true
4+
5+
health-check:
6+
listen: 0.0.0.0:8088
7+
enabled: true
8+
9+
homepage:
10+
enabled: false
11+
12+
sandbox:
13+
enabled: true
14+
115
supergraph:
216
listen: 0.0.0.0:4000
3-
4-
cors:
5-
allow_credentials: true
17+
introspection: true

src/utils/client.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import fetch from "make-fetch-happen";
33
export const ROUTER_URL = "http://localhost:4000/";
44
const PING_QUERY = "query { __typename }";
55

6-
const routerHealthCheck =
7-
"http://localhost:4000/.well-known/apollo/server-health";
8-
const productsUrl = "http://localhost:4001/";
6+
const ROUTER_HEALTH_URL = "http://localhost:8088/health";
7+
const PRODUCTS_URL = "http://localhost:4001/";
98

109
export async function graphqlRequest(
1110
url: string,
@@ -40,7 +39,7 @@ export function productsRequest(
4039
},
4140
headers?: { [key: string]: any }
4241
) {
43-
return graphqlRequest(productsUrl, req, headers);
42+
return graphqlRequest(PRODUCTS_URL, req, headers);
4443
}
4544

4645
export function routerRequest(
@@ -55,7 +54,8 @@ export function routerRequest(
5554
}
5655

5756
export async function ping(): Promise<boolean> {
58-
const routerPing = await fetch(routerHealthCheck, { retry: 10 });
57+
console.log("router health check", ROUTER_HEALTH_URL)
58+
const routerPing = await fetch(ROUTER_HEALTH_URL, { retry: { retries: 10, maxTimeout: 1000 } });
5959

6060
if (!routerPing.ok) {
6161
console.log("router failed to start");
@@ -65,8 +65,9 @@ export async function ping(): Promise<boolean> {
6565
let attempts = 100;
6666
let lastError = null;
6767
while (attempts--) {
68+
console.log("products health check", ROUTER_HEALTH_URL)
6869
try {
69-
const implementationPing = await graphqlRequest(productsUrl, {
70+
const implementationPing = await graphqlRequest(PRODUCTS_URL, {
7071
query: PING_QUERY,
7172
});
7273

supergraph.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type Product
8080
package: String @join__field(graph: PRODUCTS)
8181
variation: ProductVariation @join__field(graph: PRODUCTS)
8282
createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated")
83-
notes: String @tag(name: "internal") @join__field(graph: PRODUCTS)
83+
notes: String @join__field(graph: PRODUCTS) @tag(name: "internal")
8484
research: [ProductResearch!]! @join__field(graph: PRODUCTS)
8585
}
8686

@@ -112,7 +112,7 @@ type Query
112112
@join__type(graph: USERS)
113113
{
114114
product(id: ID!): Product @join__field(graph: PRODUCTS)
115-
deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @deprecated(reason: "Use product query instead") @join__field(graph: PRODUCTS)
115+
deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @join__field(graph: PRODUCTS) @deprecated(reason: "Use product query instead")
116116
}
117117

118118
type User

0 commit comments

Comments
 (0)