From 829510847610667105bdf82549555b07699de5ba Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 12:03:34 +0300 Subject: [PATCH 1/7] fix(cli): override CLI defaults from configuration --- packages/gateway/src/cli.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gateway/src/cli.ts b/packages/gateway/src/cli.ts index bb5f78a81..705ede212 100644 --- a/packages/gateway/src/cli.ts +++ b/packages/gateway/src/cli.ts @@ -225,10 +225,9 @@ let cli = new Command() .addOption( new Option( '--fork ', - `count of workers to spawn. uses "${maxFork}" (available parallelism) workers when NODE_ENV is "production", otherwise "1" (the main) worker`, + `count of workers to spawn. uses "${maxFork}" (available parallelism) workers when NODE_ENV is "production", otherwise "1" (the main) worker (default: ${defaultOptions.fork})`, ) .env('FORK') - .default(defaultOptions.fork) .argParser((v) => { const count = parseInt(v); if (isNaN(count)) { @@ -249,15 +248,17 @@ let cli = new Command() ).env('CONFIG_PATH'), ) .addOption( - new Option('-h, --host ', `host to use for serving`).default( - defaultOptions.host, - defaultOptions.host, + new Option( + '-h, --host ', + `host to use for serving (default: ${defaultOptions.host})`, ), ) .addOption( - new Option('-p, --port ', `port to use for serving`) + new Option( + '-p, --port ', + `port to use for serving (default: ${defaultOptions.port})`, + ) .env('PORT') - .default(defaultOptions.port) .argParser((v) => { const port = parseInt(v); if (isNaN(port)) { @@ -269,9 +270,8 @@ let cli = new Command() .addOption( new Option( '--polling ', - `schema polling interval in human readable duration`, + `schema polling interval in human readable duration (default: 10s)`, ) - .default(10_000, '10s') .env('POLLING') .argParser((v) => { const interval = parseDuration(v) as number; From e9a95141709b612848c5590207995d9ef63852ee Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 12:37:55 +0300 Subject: [PATCH 2/7] Apply defaults for polling interval correctly --- packages/gateway/src/commands/proxy.ts | 2 +- packages/gateway/src/commands/subgraph.ts | 2 +- packages/gateway/src/commands/supergraph.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gateway/src/commands/proxy.ts b/packages/gateway/src/commands/proxy.ts index cd58c5a6e..35ed5daf5 100644 --- a/packages/gateway/src/commands/proxy.ts +++ b/packages/gateway/src/commands/proxy.ts @@ -121,7 +121,7 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling, + pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, ...(hiveRegistryToken ? { reporting: { diff --git a/packages/gateway/src/commands/subgraph.ts b/packages/gateway/src/commands/subgraph.ts index 77979f61b..ccf545652 100644 --- a/packages/gateway/src/commands/subgraph.ts +++ b/packages/gateway/src/commands/subgraph.ts @@ -82,7 +82,7 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling, + pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, ...(hiveRegistryToken ? { reporting: { diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index 3b24ec2be..a643cc5c7 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -206,7 +206,7 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling, + pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, ...registryConfig, supergraph, logging: ctx.log, From 150b644d33f685dedc26c4a84ff2d1f4b304bff4 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 12:38:17 +0300 Subject: [PATCH 3/7] Format --- packages/gateway/src/commands/proxy.ts | 7 ++++++- packages/gateway/src/commands/subgraph.ts | 7 ++++++- packages/gateway/src/commands/supergraph.ts | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/gateway/src/commands/proxy.ts b/packages/gateway/src/commands/proxy.ts index 35ed5daf5..004b18f2c 100644 --- a/packages/gateway/src/commands/proxy.ts +++ b/packages/gateway/src/commands/proxy.ts @@ -121,7 +121,12 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, + pollingInterval: + opts.polling || + ('pollingInterval' in loadedConfig + ? loadedConfig.pollingInterval + : undefined) || + defaultOptions.pollingInterval, ...(hiveRegistryToken ? { reporting: { diff --git a/packages/gateway/src/commands/subgraph.ts b/packages/gateway/src/commands/subgraph.ts index ccf545652..5e06dfa46 100644 --- a/packages/gateway/src/commands/subgraph.ts +++ b/packages/gateway/src/commands/subgraph.ts @@ -82,7 +82,12 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, + pollingInterval: + opts.polling || + ('pollingInterval' in loadedConfig + ? loadedConfig.pollingInterval + : undefined) || + defaultOptions.pollingInterval, ...(hiveRegistryToken ? { reporting: { diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index a643cc5c7..8a392a92c 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -206,7 +206,12 @@ export const addCommand: AddCommand = (ctx, cli) => ...defaultOptions, ...loadedConfig, ...opts, - pollingInterval: opts.polling || ('pollingInterval' in loadedConfig ? loadedConfig.pollingInterval : undefined) || defaultOptions.pollingInterval, + pollingInterval: + opts.polling || + ('pollingInterval' in loadedConfig + ? loadedConfig.pollingInterval + : undefined) || + defaultOptions.pollingInterval, ...registryConfig, supergraph, logging: ctx.log, From 86221e6188cf6ca21780521b191e63bef5e44e46 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 12:50:23 +0300 Subject: [PATCH 4/7] .. --- e2e/polling/gateway.config.ts | 1 - packages/gateway/src/commands/proxy.ts | 23 +++++------------- packages/gateway/src/commands/subgraph.ts | 2 +- packages/gateway/src/commands/supergraph.ts | 26 +++++---------------- 4 files changed, 13 insertions(+), 39 deletions(-) diff --git a/e2e/polling/gateway.config.ts b/e2e/polling/gateway.config.ts index 86919024d..6987c68d1 100644 --- a/e2e/polling/gateway.config.ts +++ b/e2e/polling/gateway.config.ts @@ -8,5 +8,4 @@ export const gatewayConfig = defineConfig({ console.log(`[${new Date().toISOString()}]`, 'Reading ' + SUPERGRAPH_PATH); return fs.promises.readFile(SUPERGRAPH_PATH, 'utf8'); }, - pollingInterval: 5_000, }); diff --git a/packages/gateway/src/commands/proxy.ts b/packages/gateway/src/commands/proxy.ts index 004b18f2c..09e5785ae 100644 --- a/packages/gateway/src/commands/proxy.ts +++ b/packages/gateway/src/commands/proxy.ts @@ -1,24 +1,13 @@ import cluster from 'node:cluster'; -import { - createGatewayRuntime, - type GatewayConfigProxy, -} from '@graphql-hive/gateway-runtime'; +import { createGatewayRuntime, type GatewayConfigProxy } from '@graphql-hive/gateway-runtime'; import { isUrl, PubSub } from '@graphql-mesh/utils'; -import { - defaultOptions, - type AddCommand, - type CLIContext, - type GatewayCLIConfig, -} from '../cli'; -import { - getBuiltinPluginsFromConfig, - getCacheInstanceFromConfig, - loadConfig, -} from '../config'; +import { defaultOptions, type AddCommand, type CLIContext, type GatewayCLIConfig } from '../cli'; +import { getBuiltinPluginsFromConfig, getCacheInstanceFromConfig, loadConfig } from '../config'; import { startServerForRuntime } from '../servers/startServerForRuntime'; import { handleFork } from './handleFork'; import { handleLoggingConfig } from './handleLoggingOption'; + export const addCommand: AddCommand = (ctx, cli) => cli .command('proxy') @@ -180,7 +169,7 @@ export const addCommand: AddCommand = (ctx, cli) => config.pollingInterval < 10_000 ) { process.stderr.write( - `error: polling interval duration too short, use at least 10 seconds\n`, + `error: polling interval duration too short ${config.pollingInterval}, use at least 10 seconds\n`, ); process.exit(1); } @@ -202,4 +191,4 @@ export async function runProxy({ log }: CLIContext, config: ProxyConfig) { ...config, log, }); -} +} \ No newline at end of file diff --git a/packages/gateway/src/commands/subgraph.ts b/packages/gateway/src/commands/subgraph.ts index 5e06dfa46..08331c7c6 100644 --- a/packages/gateway/src/commands/subgraph.ts +++ b/packages/gateway/src/commands/subgraph.ts @@ -140,7 +140,7 @@ export const addCommand: AddCommand = (ctx, cli) => config.pollingInterval < 10_000 ) { process.stderr.write( - `error: polling interval duration too short, use at least 10 seconds\n`, + `error: polling interval duration too short ${config.pollingInterval}, use at least 10 seconds\n`, ); process.exit(1); } diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index 8a392a92c..2b7fe0b12 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -2,33 +2,19 @@ import cluster from 'node:cluster'; import { lstat } from 'node:fs/promises'; import { dirname, isAbsolute, resolve } from 'node:path'; import { Option } from '@commander-js/extra-typings'; -import { - createGatewayRuntime, - type GatewayConfigSupergraph, - type GatewayGraphOSManagedFederationOptions, - type GatewayHiveCDNOptions, - type UnifiedGraphConfig, -} from '@graphql-hive/gateway-runtime'; +import { createGatewayRuntime, type GatewayConfigSupergraph, type GatewayGraphOSManagedFederationOptions, type GatewayHiveCDNOptions, type UnifiedGraphConfig } from '@graphql-hive/gateway-runtime'; import { isUrl, PubSub, registerTerminateHandler } from '@graphql-mesh/utils'; import { CodeFileLoader } from '@graphql-tools/code-file-loader'; import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'; import { loadTypedefs } from '@graphql-tools/load'; import { asArray, isValidPath } from '@graphql-tools/utils'; -import { - defaultOptions, - type AddCommand, - type CLIContext, - type GatewayCLIConfig, -} from '../cli'; -import { - getBuiltinPluginsFromConfig, - getCacheInstanceFromConfig, - loadConfig, -} from '../config'; +import { defaultOptions, type AddCommand, type CLIContext, type GatewayCLIConfig } from '../cli'; +import { getBuiltinPluginsFromConfig, getCacheInstanceFromConfig, loadConfig } from '../config'; import { startServerForRuntime } from '../servers/startServerForRuntime'; import { handleFork } from './handleFork'; import { handleLoggingConfig } from './handleLoggingOption'; + export const addCommand: AddCommand = (ctx, cli) => cli .command('supergraph') @@ -256,7 +242,7 @@ export const addCommand: AddCommand = (ctx, cli) => config.pollingInterval < 10_000 ) { process.stderr.write( - `error: polling interval duration too short, use at least 10 seconds\n`, + `error: polling interval duration too short ${config.pollingInterval}, use at least 10 seconds\n`, ); process.exit(1); } @@ -401,4 +387,4 @@ export async function runSupergraph( ...config, log, }); -} +} \ No newline at end of file From 131cd2775d671bd8c7d068bb2f73292c63bd7db8 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 12:50:52 +0300 Subject: [PATCH 5/7] .. --- packages/gateway/src/commands/proxy.ts | 21 +++++++++++++----- packages/gateway/src/commands/supergraph.ts | 24 ++++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/packages/gateway/src/commands/proxy.ts b/packages/gateway/src/commands/proxy.ts index 09e5785ae..318d3b193 100644 --- a/packages/gateway/src/commands/proxy.ts +++ b/packages/gateway/src/commands/proxy.ts @@ -1,13 +1,24 @@ import cluster from 'node:cluster'; -import { createGatewayRuntime, type GatewayConfigProxy } from '@graphql-hive/gateway-runtime'; +import { + createGatewayRuntime, + type GatewayConfigProxy, +} from '@graphql-hive/gateway-runtime'; import { isUrl, PubSub } from '@graphql-mesh/utils'; -import { defaultOptions, type AddCommand, type CLIContext, type GatewayCLIConfig } from '../cli'; -import { getBuiltinPluginsFromConfig, getCacheInstanceFromConfig, loadConfig } from '../config'; +import { + defaultOptions, + type AddCommand, + type CLIContext, + type GatewayCLIConfig, +} from '../cli'; +import { + getBuiltinPluginsFromConfig, + getCacheInstanceFromConfig, + loadConfig, +} from '../config'; import { startServerForRuntime } from '../servers/startServerForRuntime'; import { handleFork } from './handleFork'; import { handleLoggingConfig } from './handleLoggingOption'; - export const addCommand: AddCommand = (ctx, cli) => cli .command('proxy') @@ -191,4 +202,4 @@ export async function runProxy({ log }: CLIContext, config: ProxyConfig) { ...config, log, }); -} \ No newline at end of file +} diff --git a/packages/gateway/src/commands/supergraph.ts b/packages/gateway/src/commands/supergraph.ts index 2b7fe0b12..d5cfa9dd5 100644 --- a/packages/gateway/src/commands/supergraph.ts +++ b/packages/gateway/src/commands/supergraph.ts @@ -2,19 +2,33 @@ import cluster from 'node:cluster'; import { lstat } from 'node:fs/promises'; import { dirname, isAbsolute, resolve } from 'node:path'; import { Option } from '@commander-js/extra-typings'; -import { createGatewayRuntime, type GatewayConfigSupergraph, type GatewayGraphOSManagedFederationOptions, type GatewayHiveCDNOptions, type UnifiedGraphConfig } from '@graphql-hive/gateway-runtime'; +import { + createGatewayRuntime, + type GatewayConfigSupergraph, + type GatewayGraphOSManagedFederationOptions, + type GatewayHiveCDNOptions, + type UnifiedGraphConfig, +} from '@graphql-hive/gateway-runtime'; import { isUrl, PubSub, registerTerminateHandler } from '@graphql-mesh/utils'; import { CodeFileLoader } from '@graphql-tools/code-file-loader'; import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'; import { loadTypedefs } from '@graphql-tools/load'; import { asArray, isValidPath } from '@graphql-tools/utils'; -import { defaultOptions, type AddCommand, type CLIContext, type GatewayCLIConfig } from '../cli'; -import { getBuiltinPluginsFromConfig, getCacheInstanceFromConfig, loadConfig } from '../config'; +import { + defaultOptions, + type AddCommand, + type CLIContext, + type GatewayCLIConfig, +} from '../cli'; +import { + getBuiltinPluginsFromConfig, + getCacheInstanceFromConfig, + loadConfig, +} from '../config'; import { startServerForRuntime } from '../servers/startServerForRuntime'; import { handleFork } from './handleFork'; import { handleLoggingConfig } from './handleLoggingOption'; - export const addCommand: AddCommand = (ctx, cli) => cli .command('supergraph') @@ -387,4 +401,4 @@ export async function runSupergraph( ...config, log, }); -} \ No newline at end of file +} From 4856edd8a66d955da38456c7141e2287daf10e74 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 14:35:18 +0300 Subject: [PATCH 6/7] Changeset --- .changeset/dull-mayflies-allow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-mayflies-allow.md diff --git a/.changeset/dull-mayflies-allow.md b/.changeset/dull-mayflies-allow.md new file mode 100644 index 000000000..911127308 --- /dev/null +++ b/.changeset/dull-mayflies-allow.md @@ -0,0 +1,5 @@ +--- +'@graphql-hive/gateway': patch +--- + +Fix the regression causing `pollingInterval` in the configuration is overriden by the default values of CLI parameters From 1788b6d693689dafcf968053afe59a04d765d263 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 31 Jan 2025 14:36:30 +0300 Subject: [PATCH 7/7] Changeset --- .changeset/dull-mayflies-allow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-mayflies-allow.md b/.changeset/dull-mayflies-allow.md index 911127308..92de40ebc 100644 --- a/.changeset/dull-mayflies-allow.md +++ b/.changeset/dull-mayflies-allow.md @@ -2,4 +2,4 @@ '@graphql-hive/gateway': patch --- -Fix the regression causing `pollingInterval` in the configuration is overriden by the default values of CLI parameters +Fix the regression causing `port`, `host` and `pollingInterval` in the configuration is overriden by the default values of CLI parameters