Fix watcher endpoints check in gateway server (#19)

This commit is contained in:
Nabarun Gogoi 2023-05-04 15:08:51 +05:30 committed by GitHub
parent 86fe1c03af
commit c420078ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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'
}
});