Skip to content

Commit

Permalink
fix(cli): override CLI defaults from configuration (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Jan 31, 2025
1 parent 73abe12 commit 8c466f4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-mayflies-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/gateway': patch
---

Fix the regression causing `port`, `host` and `pollingInterval` in the configuration is overriden by the default values of CLI parameters
1 change: 0 additions & 1 deletion e2e/polling/gateway.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
18 changes: 9 additions & 9 deletions packages/gateway/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ let cli = new Command()
.addOption(
new Option(
'--fork <count>',
`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)) {
Expand All @@ -249,15 +248,17 @@ let cli = new Command()
).env('CONFIG_PATH'),
)
.addOption(
new Option('-h, --host <hostname>', `host to use for serving`).default(
defaultOptions.host,
defaultOptions.host,
new Option(
'-h, --host <hostname>',
`host to use for serving (default: ${defaultOptions.host})`,
),
)
.addOption(
new Option('-p, --port <number>', `port to use for serving`)
new Option(
'-p, --port <number>',
`port to use for serving (default: ${defaultOptions.port})`,
)
.env('PORT')
.default(defaultOptions.port)
.argParser((v) => {
const port = parseInt(v);
if (isNaN(port)) {
Expand All @@ -269,9 +270,8 @@ let cli = new Command()
.addOption(
new Option(
'--polling <duration>',
`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;
Expand Down
9 changes: 7 additions & 2 deletions packages/gateway/src/commands/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ 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: {
Expand Down Expand Up @@ -175,7 +180,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);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/gateway/src/commands/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ 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: {
Expand Down Expand Up @@ -135,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);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/gateway/src/commands/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ 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,
Expand Down Expand Up @@ -251,7 +256,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);
}
Expand Down

0 comments on commit 8c466f4

Please sign in to comment.