From c420078ad5483f5e5a974f8a4103b885d4da38e9 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Thu, 4 May 2023 15:08:51 +0530 Subject: [PATCH] Fix watcher endpoints check in gateway server (#19) --- packages/gateway-server/README.md | 8 +++++++- packages/gateway-server/src/gateway.ts | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/gateway-server/README.md b/packages/gateway-server/README.md index 11157a1..9181356 100644 --- a/packages/gateway-server/README.md +++ b/packages/gateway-server/README.md @@ -1,3 +1,9 @@ # gateway-server -Reference: https://github.com/ardatan/schema-stitching/blob/master/examples/combining-local-and-remote-schemas +GQL server to proxy queries to their respective watchers + +Queries from a watcher are prefixed according to the [watchers.json](./src/watchers.json) file + +## References + +- https://github.com/ardatan/schema-stitching/blob/master/examples/combining-local-and-remote-schemas diff --git a/packages/gateway-server/src/gateway.ts b/packages/gateway-server/src/gateway.ts index e0961bb..f0dd8d6 100644 --- a/packages/gateway-server/src/gateway.ts +++ b/packages/gateway-server/src/gateway.ts @@ -4,6 +4,8 @@ import { createYoga } from 'graphql-yoga'; import isReachable from 'is-reachable'; +import assert from 'assert'; +import { URL } from 'url'; import { buildHTTPExecutor } from '@graphql-tools/executor-http'; import { stitchSchemas } from '@graphql-tools/stitch'; @@ -13,7 +15,14 @@ import watchers from './watchers.json'; async function makeGatewaySchema () { // Check that watcher endpoints are reachable. - await isReachable(watchers.map(watcher => watcher.endpoint)); + for (const watcher of watchers) { + const url = new URL(watcher.endpoint); + + assert( + await isReachable(`${url.hostname}:${url.port}`), + `Watcher endpoint ${watcher.endpoint} is not reachable.` + ); + } const subSchemaPromises = watchers.map(async watcher => { // Make remote executor: @@ -44,6 +53,6 @@ export const gatewayApp = createYoga({ schema: makeGatewaySchema(), maskedErrors: false, graphiql: { - title: 'Azimuth watchers' + title: 'Azimuth Watchers' } });