Skip to content

Commit

Permalink
Fix watcher endpoints check in gateway server (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed May 4, 2023
1 parent 86fe1c0 commit c420078
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/gateway-server/README.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions packages/gateway-server/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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:
Expand Down Expand Up @@ -44,6 +53,6 @@ export const gatewayApp = createYoga({
schema: makeGatewaySchema(),
maskedErrors: false,
graphiql: {
title: 'Azimuth watchers'
title: 'Azimuth Watchers'
}
});

0 comments on commit c420078

Please sign in to comment.