From 8e74782e07f7cd0d86020865af195c333a7b403a Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 17 Dec 2024 10:56:22 +0300 Subject: [PATCH] .. --- .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 71cbbd1a..51936f76 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 {