From be512fae9eb5c3a8650738a62d6d1f46fc21c26f Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Mon, 16 Dec 2024 13:49:18 +0300 Subject: [PATCH 01/22] Reproduction #310 --- e2e/self-hosting-hive/gateway.config.ts | 22 +++++++++++++++++ e2e/self-hosting-hive/package.json | 8 +++++++ .../self-hosting-hive.e2e.ts | 24 +++++++++++++++++++ .../services/selfHostingHive.ts | 23 ++++++++++++++++++ internal/e2e/src/tenv.ts | 18 +++++++++++--- packages/gateway/src/cli.ts | 3 +-- packages/gateway/src/commands/supergraph.ts | 4 +++- yarn.lock | 9 +++++++ 8 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 e2e/self-hosting-hive/gateway.config.ts create mode 100644 e2e/self-hosting-hive/package.json create mode 100644 e2e/self-hosting-hive/self-hosting-hive.e2e.ts create mode 100644 e2e/self-hosting-hive/services/selfHostingHive.ts diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts new file mode 100644 index 00000000..4fbc2d30 --- /dev/null +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -0,0 +1,22 @@ +import { defineConfig } from '@graphql-hive/gateway'; +import { Opts } from '@internal/testing'; + +const opts = Opts(process.argv); +const selfHostingPort = opts.getServicePort('selfHostingHive'); + +export const gatewayConfig = defineConfig({ + reporting: { + type: 'hive', + token: 'secret', + agent: { + maxRetries: 1, + maxSize: 1, + timeout: 200, + }, + selfHosting: { + applicationUrl: `http://localhost:${selfHostingPort}`, + graphqlEndpoint: `http://localhost:${selfHostingPort}/graphql`, + usageEndpoint: `http://localhost:${selfHostingPort}/usage`, + }, + }, +}); diff --git a/e2e/self-hosting-hive/package.json b/e2e/self-hosting-hive/package.json new file mode 100644 index 00000000..70e03825 --- /dev/null +++ b/e2e/self-hosting-hive/package.json @@ -0,0 +1,8 @@ +{ + "name": "@e2e/self-hosting-hive", + "private": true, + "dependencies": { + "@graphql-hive/gateway": "workspace:*", + "graphql": "16.9.0" + } +} diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts new file mode 100644 index 00000000..077a9191 --- /dev/null +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -0,0 +1,24 @@ +import { setTimeout } from 'node:timers/promises'; +import { createExampleSetup, createTenv } from '@internal/e2e'; +import { describe, expect, it } from 'vitest'; + +describe('Self Hosting Hive', () => { + const { gateway, service } = createTenv(__dirname); + const { supergraph, query, result } = createExampleSetup(__dirname); + it('usage', async () => { + const selfHostingHive = await service('selfHostingHive'); + await using gw = await gateway({ + supergraph: await supergraph(), + services: [selfHostingHive], + }); + await expect( + gw.execute({ + query, + }), + ).resolves.toEqual(result); + await setTimeout(300); + const incomingData = selfHostingHive.getStd('out'); + // Check if `/usage` endpoint receives the POST request + expect(incomingData).toContain('POST /usage'); + }); +}); diff --git a/e2e/self-hosting-hive/services/selfHostingHive.ts b/e2e/self-hosting-hive/services/selfHostingHive.ts new file mode 100644 index 00000000..4aa0acee --- /dev/null +++ b/e2e/self-hosting-hive/services/selfHostingHive.ts @@ -0,0 +1,23 @@ +import { createServer } from 'http'; +import { Opts } from '@internal/testing'; + +const opts = Opts(process.argv); +const selfHostingPort = opts.getServicePort('selfHostingHive'); + +// Echo server + +createServer((req, res) => { + process.stdout.write(`${req.method} ${req.url}\n`); + res.writeHead(200, req.headers); + req.on('data', (chunk) => { + process.stdout.write(chunk); + res.write(chunk); + }); + req.on('end', () => { + res.end(); + }); +}).listen(selfHostingPort, () => { + process.stderr.write( + `Echo server listening on http://localhost:${selfHostingPort}\n`, + ); +}); diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index 425f9b08..582738e9 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -10,8 +10,7 @@ import { RemoteGraphQLDataSource, type ServiceEndpointDefinition, } from '@apollo/gateway'; -import { createDeferred } from '@graphql-tools/delegate'; -import { fakePromise } from '@graphql-tools/utils'; +import { createDeferred, fakePromise } from '@graphql-tools/utils'; import { boolEnv, createOpt, @@ -147,6 +146,7 @@ export interface ServeOptions extends ProcOptions { /** "docker" specific options. */ docker?: Partial>; }; + services?: Service[]; } export interface Gateway extends Server { @@ -358,6 +358,7 @@ export function createTenv(cwd: string): Tenv { env, runner, args = [], + services, } = opts || {}; let proc: Proc, @@ -471,6 +472,9 @@ export function createTenv(cwd: string): Tenv { createPortOpt(port), ...(supergraph ? ['supergraph', supergraph] : []), ...(subgraph ? ['subgraph', subgraph] : []), + ...(services?.map(({ name, port }) => + createServicePortOpt(name, port), + ) || []), ...args, ], volumes, @@ -485,6 +489,9 @@ export function createTenv(cwd: string): Tenv { path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), ...(supergraph ? ['supergraph', supergraph] : []), ...(subgraph ? ['subgraph', subgraph] : []), + ...(services?.map(({ name, port }) => + createServicePortOpt(name, port), + ) || []), ...args, createPortOpt(port), ); @@ -497,6 +504,9 @@ export function createTenv(cwd: string): Tenv { path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), ...(supergraph ? ['supergraph', supergraph] : []), ...(subgraph ? ['subgraph', subgraph] : []), + ...(services?.map(({ name, port }) => + createServicePortOpt(name, port), + ) || []), ...args, createPortOpt(port), ); @@ -986,7 +996,9 @@ function spawn( // process ended _and_ the stdio streams have been closed if (code) { exitDeferred.reject( - new Error(`Exit code ${code}\n${trimError(stdboth)}`), + new Error( + `Exit code ${code} from ${cmd} ${args.join(' ')}\n${trimError(stdboth)}`, + ), ); } else { exitDeferred.resolve(); diff --git a/packages/gateway/src/cli.ts b/packages/gateway/src/cli.ts index 1865afbe..ab8b92f7 100644 --- a/packages/gateway/src/cli.ts +++ b/packages/gateway/src/cli.ts @@ -325,8 +325,7 @@ export async function run(userCtx: Partial) { }; const { binName, productDescription, version } = ctx; - cli = cli.name(binName).description(productDescription); - cli.version(version); + cli = cli.name(binName).description(productDescription).version(version); if (cluster.worker?.id) { ctx.log = ctx.log.child(`Worker #${cluster.worker.id}`); diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index 9dba8840..43164b4f 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -249,7 +249,9 @@ export const addCommand: AddCommand = (ctx, cli) => process.exit(1); } return runSupergraph(ctx, config); - }); + }) + .allowUnknownOption(process.env.NODE_ENV === 'test') + .allowExcessArguments(process.env.NODE_ENV === 'test'); export type SupergraphConfig = GatewayConfigSupergraph & GatewayCLIConfig; diff --git a/yarn.lock b/yarn.lock index a1187f72..222f6bba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2547,6 +2547,15 @@ __metadata: languageName: unknown linkType: soft +"@e2e/self-hosting-hive@workspace:e2e/self-hosting-hive": + version: 0.0.0-use.local + resolution: "@e2e/self-hosting-hive@workspace:e2e/self-hosting-hive" + dependencies: + "@graphql-hive/gateway": "workspace:*" + graphql: "npm:16.9.0" + languageName: unknown + linkType: soft + "@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation": version: 0.0.0-use.local resolution: "@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation" From 86e27f3069eb6d4d32dab826bb191447578c41a0 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 10:56:22 +0300 Subject: [PATCH 02/22] .. --- .changeset/fuzzy-eels-obey.md | 7 +++++++ .changeset/sixty-rice-give.md | 5 +++++ e2e/self-hosting-hive/gateway.config.ts | 1 - e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 3 +++ e2e/self-hosting-hive/services/selfHostingHive.ts | 12 ++++++++---- packages/gateway/src/commands/supergraph.ts | 1 + packages/runtime/src/types.ts | 2 -- 7 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .changeset/fuzzy-eels-obey.md create mode 100644 .changeset/sixty-rice-give.md diff --git a/.changeset/fuzzy-eels-obey.md b/.changeset/fuzzy-eels-obey.md new file mode 100644 index 00000000..6b51b86e --- /dev/null +++ b/.changeset/fuzzy-eels-obey.md @@ -0,0 +1,7 @@ +--- +'@graphql-hive/gateway': patch +--- + +Respect both registry token from CLI arguments and the configuration in the \`gateway.config\` + +User can provide the token in the CLI arguments, and have some registry configuration in \`gateway.config\` \ No newline at end of file diff --git a/.changeset/sixty-rice-give.md b/.changeset/sixty-rice-give.md new file mode 100644 index 00000000..62c383eb --- /dev/null +++ b/.changeset/sixty-rice-give.md @@ -0,0 +1,5 @@ +--- +'@graphql-hive/gateway-runtime': patch +--- + +`token` doesn't need to be required for Hive reporting in the configuration because it can be provided by the arguments diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index 4fbc2d30..acdaaf17 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -7,7 +7,6 @@ const selfHostingPort = opts.getServicePort('selfHostingHive'); export const gatewayConfig = defineConfig({ reporting: { type: 'hive', - token: 'secret', agent: { maxRetries: 1, maxSize: 1, diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index 077a9191..34b25695 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -3,6 +3,7 @@ import { createExampleSetup, createTenv } from '@internal/e2e'; import { describe, expect, it } from 'vitest'; describe('Self Hosting Hive', () => { + const TEST_TOKEN = 'my-token'; const { gateway, service } = createTenv(__dirname); const { supergraph, query, result } = createExampleSetup(__dirname); it('usage', async () => { @@ -10,6 +11,7 @@ describe('Self Hosting Hive', () => { await using gw = await gateway({ supergraph: await supergraph(), services: [selfHostingHive], + args: ['--hive-registry-token', TEST_TOKEN], }); await expect( gw.execute({ @@ -20,5 +22,6 @@ describe('Self Hosting Hive', () => { const incomingData = selfHostingHive.getStd('out'); // Check if `/usage` endpoint receives the POST request expect(incomingData).toContain('POST /usage'); + expect(incomingData).toContain(`"authorization":"Bearer ${TEST_TOKEN}"`); }); }); diff --git a/e2e/self-hosting-hive/services/selfHostingHive.ts b/e2e/self-hosting-hive/services/selfHostingHive.ts index 4aa0acee..9f7b0ca5 100644 --- a/e2e/self-hosting-hive/services/selfHostingHive.ts +++ b/e2e/self-hosting-hive/services/selfHostingHive.ts @@ -7,13 +7,17 @@ const selfHostingPort = opts.getServicePort('selfHostingHive'); // Echo server createServer((req, res) => { - process.stdout.write(`${req.method} ${req.url}\n`); + function echo(msg: string) { + process.stdout.write(msg); + res.write(msg); + } res.writeHead(200, req.headers); + echo(`${req.method} ${req.url}\n`); + echo(`headers: ${JSON.stringify(req.headers)}\n`); req.on('data', (chunk) => { - process.stdout.write(chunk); - res.write(chunk); + echo(chunk.toString('utf8')); }); - req.on('end', () => { + req.once('end', () => { res.end(); }); }).listen(selfHostingPort, () => { diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index 43164b4f..2c3183d5 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -158,6 +158,7 @@ export const addCommand: AddCommand = (ctx, cli) => ctx.log.info(`Configuring Hive registry reporting`); registryConfig = { reporting: { + ...loadedConfig.reporting, type: 'hive', token: hiveRegistryToken, }, diff --git a/packages/runtime/src/types.ts b/packages/runtime/src/types.ts index 719a4619..b96a2642 100644 --- a/packages/runtime/src/types.ts +++ b/packages/runtime/src/types.ts @@ -185,8 +185,6 @@ export interface GatewayHiveCDNOptions { export interface GatewayHiveReportingOptions extends Omit { type: 'hive'; - /** GraphQL Hive registry access token. */ - token: string; } export interface GatewayGraphOSOptions { From fc2d74b7adc6bc04796128c29579bc7fb3bc40c7 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 11:51:22 +0300 Subject: [PATCH 03/22] `NODE_ENV`=test --- e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index 34b25695..800ecda3 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -12,6 +12,9 @@ describe('Self Hosting Hive', () => { supergraph: await supergraph(), services: [selfHostingHive], args: ['--hive-registry-token', TEST_TOKEN], + env: { + NODE_ENV: 'test', + } }); await expect( gw.execute({ From 5c3e3f42c5289c10f2fd93c1a81855bbe012cbb5 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 11:51:41 +0300 Subject: [PATCH 04/22] Format --- e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index 800ecda3..0a8997b5 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -14,7 +14,7 @@ describe('Self Hosting Hive', () => { args: ['--hive-registry-token', TEST_TOKEN], env: { NODE_ENV: 'test', - } + }, }); await expect( gw.execute({ From 64e51384af7f6a1d3bd1cdff488f11ad70329bc1 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 12:02:18 +0300 Subject: [PATCH 05/22] Args? --- e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 5 +---- internal/e2e/src/tenv.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index 0a8997b5..553d48e6 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -11,10 +11,7 @@ describe('Self Hosting Hive', () => { await using gw = await gateway({ supergraph: await supergraph(), services: [selfHostingHive], - args: ['--hive-registry-token', TEST_TOKEN], - env: { - NODE_ENV: 'test', - }, + args: [`--hive-registry-token=${TEST_TOKEN}`], }); await expect( gw.execute({ diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index 582738e9..ed738ddb 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -469,12 +469,12 @@ export function createTenv(cwd: string): Tenv { `wget --spider http://0.0.0.0:${port}/healthcheck`, ], cmd: [ - createPortOpt(port), ...(supergraph ? ['supergraph', supergraph] : []), ...(subgraph ? ['subgraph', subgraph] : []), ...(services?.map(({ name, port }) => createServicePortOpt(name, port), ) || []), + createPortOpt(port), ...args, ], volumes, @@ -492,8 +492,8 @@ export function createTenv(cwd: string): Tenv { ...(services?.map(({ name, port }) => createServicePortOpt(name, port), ) || []), - ...args, createPortOpt(port), + ...args, ); } /* if (gatewayRunner === 'node') */ else { [proc, waitForExit] = await spawn( @@ -750,7 +750,10 @@ export function createTenv(cwd: string): Tenv { const ctr = await docker.createContainer({ name: containerName, Image: image, - Env: Object.entries(env).map(([name, value]) => `${name}=${value}`), + Env: Object.entries({ + ...process.env, + ...env, + }).map(([name, value]) => `${name}=${value}`), ExposedPorts: { [containerPort + '/tcp']: {}, ...Object.keys(additionalPorts).reduce( @@ -923,7 +926,7 @@ function spawn( stdio: ['ignore', 'pipe', 'pipe'], env: Object.entries(env).reduce( (acc, [key, val]) => ({ ...acc, [key]: String(val) }), - process.env, + { ...process.env }, ), shell, signal, From 9169a062d92501a7a6e1883cbbb707a37c6d055a Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 13:52:47 +0300 Subject: [PATCH 06/22] Less diff --- internal/e2e/src/tenv.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index ed738ddb..318efb81 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -469,12 +469,12 @@ export function createTenv(cwd: string): Tenv { `wget --spider http://0.0.0.0:${port}/healthcheck`, ], cmd: [ + createPortOpt(port), ...(supergraph ? ['supergraph', supergraph] : []), ...(subgraph ? ['subgraph', subgraph] : []), ...(services?.map(({ name, port }) => createServicePortOpt(name, port), ) || []), - createPortOpt(port), ...args, ], volumes, @@ -492,8 +492,8 @@ export function createTenv(cwd: string): Tenv { ...(services?.map(({ name, port }) => createServicePortOpt(name, port), ) || []), - createPortOpt(port), ...args, + createPortOpt(port), ); } /* if (gatewayRunner === 'node') */ else { [proc, waitForExit] = await spawn( From 271423104953de382ee444c2f95ffc595c55ba19 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 13:56:26 +0300 Subject: [PATCH 07/22] Align args --- internal/e2e/src/tenv.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index 318efb81..ab851e85 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -391,6 +391,16 @@ export function createTenv(cwd: string): Tenv { subgraph = output; } + const fullArgs = [ + createPortOpt(port), + ...(supergraph ? ['supergraph', supergraph] : []), + ...(subgraph ? ['subgraph', subgraph] : []), + ...args, + ...(services?.map(({ name, port }) => + createServicePortOpt(name, port), + ) || []), + ]; + if (gatewayRunner === 'docker' || gatewayRunner === 'bun-docker') { const volumes: ContainerOptions['volumes'] = runner?.docker?.volumes || []; @@ -468,15 +478,7 @@ export function createTenv(cwd: string): Tenv { 'CMD-SHELL', `wget --spider http://0.0.0.0:${port}/healthcheck`, ], - cmd: [ - createPortOpt(port), - ...(supergraph ? ['supergraph', supergraph] : []), - ...(subgraph ? ['subgraph', subgraph] : []), - ...(services?.map(({ name, port }) => - createServicePortOpt(name, port), - ) || []), - ...args, - ], + cmd: [...fullArgs], volumes, pipeLogs, }); @@ -487,13 +489,7 @@ export function createTenv(cwd: string): Tenv { 'npx', 'bun', path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...(supergraph ? ['supergraph', supergraph] : []), - ...(subgraph ? ['subgraph', subgraph] : []), - ...(services?.map(({ name, port }) => - createServicePortOpt(name, port), - ) || []), - ...args, - createPortOpt(port), + ...fullArgs, ); } /* if (gatewayRunner === 'node') */ else { [proc, waitForExit] = await spawn( @@ -502,13 +498,7 @@ export function createTenv(cwd: string): Tenv { '--import', 'tsx', path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...(supergraph ? ['supergraph', supergraph] : []), - ...(subgraph ? ['subgraph', subgraph] : []), - ...(services?.map(({ name, port }) => - createServicePortOpt(name, port), - ) || []), - ...args, - createPortOpt(port), + ...fullArgs, ); } From c9c7923035737bf70a57e9fb70c20e4825223055 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 14:35:27 +0300 Subject: [PATCH 08/22] Add binary runner --- internal/e2e/src/tenv.ts | 256 ++++++++++++++++++--------------- packages/gateway/src/config.ts | 2 + 2 files changed, 140 insertions(+), 118 deletions(-) diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index ab851e85..b95118d1 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -53,7 +53,7 @@ const gatewayRunner = (function getServeRunner() { runner, ) ) { - throw new Error(`Unsupported E2E gateway runner "${runner}"`); + throw new Error(`Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`); } if (runner === 'docker' && !boolEnv('CI')) { process.stderr.write(` @@ -120,27 +120,27 @@ export interface ServeOptions extends ProcOptions { * If {@link ComposeOptions} is provided, its {@link ComposeOptions.output output} will always be set to `graphql`; */ supergraph?: - | string - | { - with: 'mesh'; - services?: Service[]; - } - | { - with: 'apollo'; - services: Service[]; - }; + | string + | { + with: 'mesh'; + services?: Service[]; + } + | { + with: 'apollo'; + services: Service[]; + }; /** * Path to the subgraph file or {@link ComposeOptions} which will be used for composition with GraphQL Mesh. * If {@link ComposeOptions} is provided, its {@link ComposeOptions.output output} will always be set to `graphql`; */ subgraph?: - | string - | { - with: 'mesh'; - subgraphName: string; - services?: Service[]; - pipeLogs?: boolean | string; - }; + | string + | { + with: 'mesh'; + subgraphName: string; + services?: Service[]; + pipeLogs?: boolean | string; + }; /** {@link gatewayRunner Gateway Runner} specific options. */ runner?: { /** "docker" specific options. */ @@ -401,107 +401,127 @@ export function createTenv(cwd: string): Tenv { ) || []), ]; - if (gatewayRunner === 'docker' || gatewayRunner === 'bun-docker') { - const volumes: ContainerOptions['volumes'] = - runner?.docker?.volumes || []; + switch (gatewayRunner) { + case 'bun-docker': + case 'docker': { - if (supergraph) { - supergraph = await handleDockerHostName(supergraph, volumes); - } - if (subgraph) { - subgraph = await handleDockerHostName(subgraph, volumes); - } + const volumes: ContainerOptions['volumes'] = + runner?.docker?.volumes || []; + + if (supergraph) { + supergraph = await handleDockerHostName(supergraph, volumes); + } + if (subgraph) { + subgraph = await handleDockerHostName(subgraph, volumes); + } + + for (const configfile of await glob('gateway.config.*', { + cwd, + })) { + volumes.push({ + host: configfile, + container: `/gateway/${path.basename(configfile)}`, + }); + } + for (const dbfile of await glob('*.db', { cwd })) { + volumes.push({ + host: dbfile, + container: `/gateway/${path.basename(dbfile)}`, + }); + } + for (const additionalTypeDefFile of await glob( + ['./additionalTypeDefs/*.graphql', './additionalTypeDefs/*.ts'], + { cwd }, + )) { + volumes.push({ + host: additionalTypeDefFile, + container: `/gateway/additionalTypeDefs/${path.basename(additionalTypeDefFile)}`, + }); + } + const packageJsonExists = await fs + .stat(path.join(cwd, 'package.json')) + .then(() => true) + .catch(() => false); + if (packageJsonExists) { + volumes.push({ + host: 'package.json', + container: '/gateway/package.json', + }); + } + + const dockerfileExists = await fs + .stat( + path.join( + cwd, + gatewayRunner === 'bun-docker' + ? 'gateway_bun.Dockerfile' + : 'gateway.Dockerfile', + ), + ) + .then(() => true) + .catch(() => false); - for (const configfile of await glob('gateway.config.*', { - cwd, - })) { - volumes.push({ - host: configfile, - container: `/gateway/${path.basename(configfile)}`, + const cont = await tenv.container({ + env, + name: + 'gateway-e2e-' + + Math.random().toString(32).slice(6) + + (gatewayRunner === 'bun-docker' ? '-bun' : ''), + image: + 'ghcr.io/graphql-hive/gateway:' + + (dockerfileExists + ? // if the test contains a gateway dockerfile, use it instead of the default e2e image + `e2e.${path.basename(cwd)}` + : 'e2e') + + (gatewayRunner === 'bun-docker' ? '-bun' : ''), + // TODO: changing port from within gateway.config.ts wont work in docker runner + hostPort: port, + containerPort: port, + healthcheck: runner?.docker?.healthcheck || [ + 'CMD-SHELL', + `wget --spider http://0.0.0.0:${port}/healthcheck`, + ], + cmd: [...fullArgs], + volumes, + pipeLogs, }); + proc = cont; + break; } - for (const dbfile of await glob('*.db', { cwd })) { - volumes.push({ - host: dbfile, - container: `/gateway/${path.basename(dbfile)}`, - }); + case 'bun': { + [proc, waitForExit] = await spawn( + { env, cwd, pipeLogs }, + 'npx', + 'bun', + path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), + ...fullArgs, + ); + break; } - for (const additionalTypeDefFile of await glob( - ['./additionalTypeDefs/*.graphql', './additionalTypeDefs/*.ts'], - { cwd }, - )) { - volumes.push({ - host: additionalTypeDefFile, - container: `/gateway/additionalTypeDefs/${path.basename(additionalTypeDefFile)}`, - }); + case 'node': { + [proc, waitForExit] = await spawn( + { env, cwd, pipeLogs }, + 'node', + '--import', + 'tsx', + path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), + ...fullArgs, + ); + break; } - const packageJsonExists = await fs - .stat(path.join(cwd, 'package.json')) - .then(() => true) - .catch(() => false); - if (packageJsonExists) { - volumes.push({ - host: 'package.json', - container: '/gateway/package.json', - }); + case 'bin': { + [proc, waitForExit] = await spawn( + { env, cwd, pipeLogs }, + path.resolve(__project, 'packages', 'gateway', 'hive-gateway'), + ...fullArgs, + ); + break; } - - const dockerfileExists = await fs - .stat( - path.join( - cwd, - gatewayRunner === 'bun-docker' - ? 'gateway_bun.Dockerfile' - : 'gateway.Dockerfile', - ), - ) - .then(() => true) - .catch(() => false); - - const cont = await tenv.container({ - env, - name: - 'gateway-e2e-' + - Math.random().toString(32).slice(6) + - (gatewayRunner === 'bun-docker' ? '-bun' : ''), - image: - 'ghcr.io/graphql-hive/gateway:' + - (dockerfileExists - ? // if the test contains a gateway dockerfile, use it instead of the default e2e image - `e2e.${path.basename(cwd)}` - : 'e2e') + - (gatewayRunner === 'bun-docker' ? '-bun' : ''), - // TODO: changing port from within gateway.config.ts wont work in docker runner - hostPort: port, - containerPort: port, - healthcheck: runner?.docker?.healthcheck || [ - 'CMD-SHELL', - `wget --spider http://0.0.0.0:${port}/healthcheck`, - ], - cmd: [...fullArgs], - volumes, - pipeLogs, - }); - proc = cont; - } else if (gatewayRunner === 'bun') { - [proc, waitForExit] = await spawn( - { env, cwd, pipeLogs }, - 'npx', - 'bun', - path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...fullArgs, - ); - } /* if (gatewayRunner === 'node') */ else { - [proc, waitForExit] = await spawn( - { env, cwd, pipeLogs }, - 'node', - '--import', - 'tsx', - path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...fullArgs, - ); + default: + throw new Error(`Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`); } + const gw: Gateway = { ...proc, port, @@ -727,8 +747,8 @@ export function createTenv(cwd: string): Tenv { (err, res) => (err ? reject(err) : resolve(res)), pipeLogs ? (e) => { - process.stderr.write(JSON.stringify(e)); - } + process.stderr.write(JSON.stringify(e)); + } : undefined, ); }); @@ -774,11 +794,11 @@ export function createTenv(cwd: string): Tenv { Healthcheck: healthcheck.length > 0 ? { - Test: healthcheck, - Interval: msToNs(interval), - Timeout: 0, // dont wait between tests - Retries: retries, - } + Test: healthcheck, + Interval: msToNs(interval), + Timeout: 0, // dont wait between tests + Retries: retries, + } : undefined, abortSignal: ctrl.signal, }); @@ -887,7 +907,7 @@ export function createTenv(cwd: string): Tenv { getDataSource(opts) { return new RemoteGraphQLDataSource(opts); }, - update() {}, + update() { }, healthCheck: () => fakePromise(undefined), }); @@ -1035,7 +1055,7 @@ async function waitForPort(port: number, signal: AbortSignal) { try { await fetch(`http://${localHostname}:${port}`, { signal }); break outer; - } catch (err) {} + } catch (err) { } } // no need to track retries, jest will time out aborting the signal signal.throwIfAborted(); diff --git a/packages/gateway/src/config.ts b/packages/gateway/src/config.ts index f14b33e6..abc09207 100644 --- a/packages/gateway/src/config.ts +++ b/packages/gateway/src/config.ts @@ -54,6 +54,8 @@ export async function loadConfig< !opts.quiet && opts.log.info(`Found default config file ${absoluteConfigPath}`); const importUrl = pathToFileURL(absoluteConfigPath).toString(); + !opts.quiet && + opts.log.info(`Loading config file at path ${importUrl}`); const module = await import(importUrl); importedConfig = Object(module).gatewayConfig || null; if (!importedConfig) { From a34bd4a23e28c6bfbbb1776f87640306a9d62b44 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 14:41:51 +0300 Subject: [PATCH 09/22] Fullargs --- internal/e2e/src/tenv.ts | 90 +++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/internal/e2e/src/tenv.ts b/internal/e2e/src/tenv.ts index b95118d1..ae5ea4c6 100644 --- a/internal/e2e/src/tenv.ts +++ b/internal/e2e/src/tenv.ts @@ -53,7 +53,9 @@ const gatewayRunner = (function getServeRunner() { runner, ) ) { - throw new Error(`Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`); + throw new Error( + `Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`, + ); } if (runner === 'docker' && !boolEnv('CI')) { process.stderr.write(` @@ -120,27 +122,27 @@ export interface ServeOptions extends ProcOptions { * If {@link ComposeOptions} is provided, its {@link ComposeOptions.output output} will always be set to `graphql`; */ supergraph?: - | string - | { - with: 'mesh'; - services?: Service[]; - } - | { - with: 'apollo'; - services: Service[]; - }; + | string + | { + with: 'mesh'; + services?: Service[]; + } + | { + with: 'apollo'; + services: Service[]; + }; /** * Path to the subgraph file or {@link ComposeOptions} which will be used for composition with GraphQL Mesh. * If {@link ComposeOptions} is provided, its {@link ComposeOptions.output output} will always be set to `graphql`; */ subgraph?: - | string - | { - with: 'mesh'; - subgraphName: string; - services?: Service[]; - pipeLogs?: boolean | string; - }; + | string + | { + with: 'mesh'; + subgraphName: string; + services?: Service[]; + pipeLogs?: boolean | string; + }; /** {@link gatewayRunner Gateway Runner} specific options. */ runner?: { /** "docker" specific options. */ @@ -391,20 +393,21 @@ export function createTenv(cwd: string): Tenv { subgraph = output; } - const fullArgs = [ - createPortOpt(port), - ...(supergraph ? ['supergraph', supergraph] : []), - ...(subgraph ? ['subgraph', subgraph] : []), - ...args, - ...(services?.map(({ name, port }) => - createServicePortOpt(name, port), - ) || []), - ]; + function getFullArgs() { + return [ + createPortOpt(port), + ...(supergraph ? ['supergraph', supergraph] : []), + ...(subgraph ? ['subgraph', subgraph] : []), + ...args, + ...(services?.map(({ name, port }) => + createServicePortOpt(name, port), + ) || []), + ]; + } switch (gatewayRunner) { case 'bun-docker': case 'docker': { - const volumes: ContainerOptions['volumes'] = runner?.docker?.volumes || []; @@ -471,7 +474,7 @@ export function createTenv(cwd: string): Tenv { 'ghcr.io/graphql-hive/gateway:' + (dockerfileExists ? // if the test contains a gateway dockerfile, use it instead of the default e2e image - `e2e.${path.basename(cwd)}` + `e2e.${path.basename(cwd)}` : 'e2e') + (gatewayRunner === 'bun-docker' ? '-bun' : ''), // TODO: changing port from within gateway.config.ts wont work in docker runner @@ -481,7 +484,7 @@ export function createTenv(cwd: string): Tenv { 'CMD-SHELL', `wget --spider http://0.0.0.0:${port}/healthcheck`, ], - cmd: [...fullArgs], + cmd: getFullArgs(), volumes, pipeLogs, }); @@ -494,7 +497,7 @@ export function createTenv(cwd: string): Tenv { 'npx', 'bun', path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...fullArgs, + ...getFullArgs(), ); break; } @@ -505,7 +508,7 @@ export function createTenv(cwd: string): Tenv { '--import', 'tsx', path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'), - ...fullArgs, + ...getFullArgs(), ); break; } @@ -513,15 +516,16 @@ export function createTenv(cwd: string): Tenv { [proc, waitForExit] = await spawn( { env, cwd, pipeLogs }, path.resolve(__project, 'packages', 'gateway', 'hive-gateway'), - ...fullArgs, + ...getFullArgs(), ); break; } default: - throw new Error(`Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`); + throw new Error( + `Unsupported E2E gateway runner "${runner}"; supported runners are ${E2E_GATEWAY_RUNNERS}`, + ); } - const gw: Gateway = { ...proc, port, @@ -747,8 +751,8 @@ export function createTenv(cwd: string): Tenv { (err, res) => (err ? reject(err) : resolve(res)), pipeLogs ? (e) => { - process.stderr.write(JSON.stringify(e)); - } + process.stderr.write(JSON.stringify(e)); + } : undefined, ); }); @@ -794,11 +798,11 @@ export function createTenv(cwd: string): Tenv { Healthcheck: healthcheck.length > 0 ? { - Test: healthcheck, - Interval: msToNs(interval), - Timeout: 0, // dont wait between tests - Retries: retries, - } + Test: healthcheck, + Interval: msToNs(interval), + Timeout: 0, // dont wait between tests + Retries: retries, + } : undefined, abortSignal: ctrl.signal, }); @@ -907,7 +911,7 @@ export function createTenv(cwd: string): Tenv { getDataSource(opts) { return new RemoteGraphQLDataSource(opts); }, - update() { }, + update() {}, healthCheck: () => fakePromise(undefined), }); @@ -1055,7 +1059,7 @@ async function waitForPort(port: number, signal: AbortSignal) { try { await fetch(`http://${localHostname}:${port}`, { signal }); break outer; - } catch (err) { } + } catch (err) {} } // no need to track retries, jest will time out aborting the signal signal.throwIfAborted(); From 8763847990c1f0caea6d6c8be4d19949488368a1 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 18 Dec 2024 17:39:08 +0300 Subject: [PATCH 10/22] Update packages/gateway/src/config.ts Co-authored-by: Denis Badurina --- packages/gateway/src/config.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/gateway/src/config.ts b/packages/gateway/src/config.ts index abc09207..3189d426 100644 --- a/packages/gateway/src/config.ts +++ b/packages/gateway/src/config.ts @@ -52,10 +52,6 @@ export async function loadConfig< .catch(() => false); if (exists) { !opts.quiet && - opts.log.info(`Found default config file ${absoluteConfigPath}`); - const importUrl = pathToFileURL(absoluteConfigPath).toString(); - !opts.quiet && - opts.log.info(`Loading config file at path ${importUrl}`); const module = await import(importUrl); importedConfig = Object(module).gatewayConfig || null; if (!importedConfig) { From 2d96745c68b5807818aed5e76c0c607fa9faa685 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 18 Dec 2024 17:39:36 +0300 Subject: [PATCH 11/22] Update config.ts --- packages/gateway/src/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gateway/src/config.ts b/packages/gateway/src/config.ts index 3189d426..fef40d62 100644 --- a/packages/gateway/src/config.ts +++ b/packages/gateway/src/config.ts @@ -52,6 +52,7 @@ export async function loadConfig< .catch(() => false); if (exists) { !opts.quiet && + opts.log.info(`Found default config file ${absoluteConfigPath}`); const module = await import(importUrl); importedConfig = Object(module).gatewayConfig || null; if (!importedConfig) { From be048294e40bb49ed880e9052761a6bd0b07b721 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 18 Dec 2024 17:40:02 +0300 Subject: [PATCH 12/22] Update config.ts --- packages/gateway/src/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gateway/src/config.ts b/packages/gateway/src/config.ts index fef40d62..f14b33e6 100644 --- a/packages/gateway/src/config.ts +++ b/packages/gateway/src/config.ts @@ -53,6 +53,7 @@ export async function loadConfig< if (exists) { !opts.quiet && opts.log.info(`Found default config file ${absoluteConfigPath}`); + const importUrl = pathToFileURL(absoluteConfigPath).toString(); const module = await import(importUrl); importedConfig = Object(module).gatewayConfig || null; if (!importedConfig) { From bae665b51f1e78896bb02beab3732f484a99b12f Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 15:47:36 +0100 Subject: [PATCH 13/22] use docker hostname --- e2e/self-hosting-hive/gateway.config.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index acdaaf17..cdcab78b 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -1,7 +1,13 @@ import { defineConfig } from '@graphql-hive/gateway'; -import { Opts } from '@internal/testing'; +import { boolEnv, Opts } from '@internal/testing'; const opts = Opts(process.argv); +const selfHostingHost = + process.env['E2E_GATEWAY_RUNNER'] === 'docker' + ? boolEnv('CI') + ? '172.17.0.1' + : 'host.docker.internal' + : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); export const gatewayConfig = defineConfig({ @@ -13,9 +19,9 @@ export const gatewayConfig = defineConfig({ timeout: 200, }, selfHosting: { - applicationUrl: `http://localhost:${selfHostingPort}`, - graphqlEndpoint: `http://localhost:${selfHostingPort}/graphql`, - usageEndpoint: `http://localhost:${selfHostingPort}/usage`, + applicationUrl: `http://${selfHostingHost}:${selfHostingPort}`, + graphqlEndpoint: `http://${selfHostingHost}:${selfHostingPort}/graphql`, + usageEndpoint: `http://${selfHostingHost}:${selfHostingPort}/usage`, }, }, }); From d6a285da63f71dbd32fc469eee84b1612299b8b2 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 15:57:35 +0100 Subject: [PATCH 14/22] try on ci --- e2e/self-hosting-hive/gateway.config.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index cdcab78b..ce993dc6 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -1,13 +1,9 @@ import { defineConfig } from '@graphql-hive/gateway'; -import { boolEnv, Opts } from '@internal/testing'; +import { Opts } from '@internal/testing'; const opts = Opts(process.argv); const selfHostingHost = - process.env['E2E_GATEWAY_RUNNER'] === 'docker' - ? boolEnv('CI') - ? '172.17.0.1' - : 'host.docker.internal' - : 'localhost'; + process.env['E2E_GATEWAY_RUNNER'] === 'docker' ? '172.17.0.1' : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); export const gatewayConfig = defineConfig({ From 56d515e46363003d48bcbec653faac0c42c96506 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:09:06 +0100 Subject: [PATCH 15/22] pipe and cat --- .github/workflows/test.yml | 2 ++ e2e/self-hosting-hive/gateway.config.ts | 13 +++++++++++-- e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31666dd7..6ca00b03 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -183,3 +183,5 @@ jobs: timeout_minutes: 10 max_attempts: 2 command: yarn test:e2e + - name: cat self-hosting-hive gw.log + run: cat e2e/self-hosting-hive/gw.log diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index ce993dc6..ba1c5a40 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -1,11 +1,20 @@ import { defineConfig } from '@graphql-hive/gateway'; -import { Opts } from '@internal/testing'; +import { boolEnv, Opts } from '@internal/testing'; const opts = Opts(process.argv); const selfHostingHost = - process.env['E2E_GATEWAY_RUNNER'] === 'docker' ? '172.17.0.1' : 'localhost'; + process.env['E2E_GATEWAY_RUNNER'] === 'docker' + ? boolEnv('CI') + ? '172.17.0.1' + : 'host.docker.internal' + : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); +console.log({ + applicationUrl: `http://${selfHostingHost}:${selfHostingPort}`, + env: process.env, +}); + export const gatewayConfig = defineConfig({ reporting: { type: 'hive', diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index 553d48e6..f05adf46 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -12,6 +12,7 @@ describe('Self Hosting Hive', () => { supergraph: await supergraph(), services: [selfHostingHive], args: [`--hive-registry-token=${TEST_TOKEN}`], + pipeLogs: 'gw.log', }); await expect( gw.execute({ From d3d518486521ca4fc47912517ef323cd65019dd7 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:15:45 +0100 Subject: [PATCH 16/22] if always --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ca00b03..0b17753d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -184,4 +184,5 @@ jobs: max_attempts: 2 command: yarn test:e2e - name: cat self-hosting-hive gw.log + if: always() run: cat e2e/self-hosting-hive/gw.log From b405ae051ec10a2fcfb2efa7d29773441f2f12cd Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:33:06 +0100 Subject: [PATCH 17/22] Revert "if always" This reverts commit 84b5cfc5fe1403a96361d992c683739feed17e06. --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b17753d..6ca00b03 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -184,5 +184,4 @@ jobs: max_attempts: 2 command: yarn test:e2e - name: cat self-hosting-hive gw.log - if: always() run: cat e2e/self-hosting-hive/gw.log From 83141e522ff835e0ae2d3beed62fe687e37d4054 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:33:10 +0100 Subject: [PATCH 18/22] Revert "pipe and cat" This reverts commit 73e8f289bc262dbfde9954adc92939b5d828c836. --- .github/workflows/test.yml | 2 -- e2e/self-hosting-hive/gateway.config.ts | 13 ++----------- e2e/self-hosting-hive/self-hosting-hive.e2e.ts | 1 - 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ca00b03..31666dd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -183,5 +183,3 @@ jobs: timeout_minutes: 10 max_attempts: 2 command: yarn test:e2e - - name: cat self-hosting-hive gw.log - run: cat e2e/self-hosting-hive/gw.log diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index ba1c5a40..ce993dc6 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -1,20 +1,11 @@ import { defineConfig } from '@graphql-hive/gateway'; -import { boolEnv, Opts } from '@internal/testing'; +import { Opts } from '@internal/testing'; const opts = Opts(process.argv); const selfHostingHost = - process.env['E2E_GATEWAY_RUNNER'] === 'docker' - ? boolEnv('CI') - ? '172.17.0.1' - : 'host.docker.internal' - : 'localhost'; + process.env['E2E_GATEWAY_RUNNER'] === 'docker' ? '172.17.0.1' : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); -console.log({ - applicationUrl: `http://${selfHostingHost}:${selfHostingPort}`, - env: process.env, -}); - export const gatewayConfig = defineConfig({ reporting: { type: 'hive', diff --git a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts index f05adf46..553d48e6 100644 --- a/e2e/self-hosting-hive/self-hosting-hive.e2e.ts +++ b/e2e/self-hosting-hive/self-hosting-hive.e2e.ts @@ -12,7 +12,6 @@ describe('Self Hosting Hive', () => { supergraph: await supergraph(), services: [selfHostingHive], args: [`--hive-registry-token=${TEST_TOKEN}`], - pipeLogs: 'gw.log', }); await expect( gw.execute({ From a53b5317123e5d1d8f680cf42f0cc271e3525979 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:33:14 +0100 Subject: [PATCH 19/22] Revert "try on ci" This reverts commit b175ad0ec8157bb52a27634f050eba8a3c310906. --- e2e/self-hosting-hive/gateway.config.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index ce993dc6..cdcab78b 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -1,9 +1,13 @@ import { defineConfig } from '@graphql-hive/gateway'; -import { Opts } from '@internal/testing'; +import { boolEnv, Opts } from '@internal/testing'; const opts = Opts(process.argv); const selfHostingHost = - process.env['E2E_GATEWAY_RUNNER'] === 'docker' ? '172.17.0.1' : 'localhost'; + process.env['E2E_GATEWAY_RUNNER'] === 'docker' + ? boolEnv('CI') + ? '172.17.0.1' + : 'host.docker.internal' + : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); export const gatewayConfig = defineConfig({ From 2bb78777f23fb2d3ce0b3634fada37eda1a19890 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 18 Dec 2024 16:33:35 +0100 Subject: [PATCH 20/22] bun is also in docker --- e2e/self-hosting-hive/gateway.config.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/e2e/self-hosting-hive/gateway.config.ts b/e2e/self-hosting-hive/gateway.config.ts index cdcab78b..bd159e15 100644 --- a/e2e/self-hosting-hive/gateway.config.ts +++ b/e2e/self-hosting-hive/gateway.config.ts @@ -2,12 +2,13 @@ import { defineConfig } from '@graphql-hive/gateway'; import { boolEnv, Opts } from '@internal/testing'; const opts = Opts(process.argv); -const selfHostingHost = - process.env['E2E_GATEWAY_RUNNER'] === 'docker' - ? boolEnv('CI') - ? '172.17.0.1' - : 'host.docker.internal' - : 'localhost'; +const selfHostingHost = String(process.env['E2E_GATEWAY_RUNNER']).includes( + 'docker', +) + ? boolEnv('CI') + ? '172.17.0.1' + : 'host.docker.internal' + : 'localhost'; const selfHostingPort = opts.getServicePort('selfHostingHive'); export const gatewayConfig = defineConfig({ From bb7e094634c170499475e08f4bb67c57f746b217 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 19 Dec 2024 14:30:46 +0300 Subject: [PATCH 21/22] Token is optional on CLI but not on runtime --- packages/gateway/src/cli.ts | 15 ++++++++++++++- packages/runtime/src/types.ts | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/gateway/src/cli.ts b/packages/gateway/src/cli.ts index ab8b92f7..2bf9d65e 100644 --- a/packages/gateway/src/cli.ts +++ b/packages/gateway/src/cli.ts @@ -12,6 +12,8 @@ import type { GatewayConfigProxy, GatewayConfigSubgraph, GatewayConfigSupergraph, + GatewayGraphOSReportingOptions, + GatewayHiveReportingOptions, } from '@graphql-hive/gateway-runtime'; import type { JWTAuthPluginOptions } from '@graphql-mesh/plugin-jwt-auth'; import type { OpenTelemetryMeshPluginOptions } from '@graphql-mesh/plugin-opentelemetry'; @@ -47,7 +49,7 @@ export type GatewayCLIConfig = ( } & GatewayCLIBuiltinPluginConfig; export interface GatewayCLISupergraphConfig - extends Omit { + extends Omit { /** * SDL, path or an URL to the Federation Supergraph. * @@ -57,6 +59,17 @@ export interface GatewayCLISupergraphConfig */ // default matches commands/supergraph.ts supergraph?: GatewayConfigSupergraph['supergraph']; + + /** Usage reporting options. */ + reporting?: GatewayHiveReportingOptions | GatewayGraphOSReportingOptions; +} + +export interface GatewayCLIHiveReportingOptions + extends Omit { + /** + * Hive registry token for usage metrics reporting. + */ + token?: GatewayHiveReportingOptions['token']; } export interface GatewayCLISubgraphConfig diff --git a/packages/runtime/src/types.ts b/packages/runtime/src/types.ts index b96a2642..719a4619 100644 --- a/packages/runtime/src/types.ts +++ b/packages/runtime/src/types.ts @@ -185,6 +185,8 @@ export interface GatewayHiveCDNOptions { export interface GatewayHiveReportingOptions extends Omit { type: 'hive'; + /** GraphQL Hive registry access token. */ + token: string; } export interface GatewayGraphOSOptions { From 8ff78beeb027abbd7fe46dcb5238a2aa1e371f96 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 19 Dec 2024 14:41:04 +0300 Subject: [PATCH 22/22] .. --- packages/gateway/src/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gateway/src/cli.ts b/packages/gateway/src/cli.ts index 2bf9d65e..e8896488 100644 --- a/packages/gateway/src/cli.ts +++ b/packages/gateway/src/cli.ts @@ -61,7 +61,7 @@ export interface GatewayCLISupergraphConfig supergraph?: GatewayConfigSupergraph['supergraph']; /** Usage reporting options. */ - reporting?: GatewayHiveReportingOptions | GatewayGraphOSReportingOptions; + reporting?: GatewayCLIHiveReportingOptions | GatewayGraphOSReportingOptions; } export interface GatewayCLIHiveReportingOptions