Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): override CLI defaults from configuration #574

Merged
merged 7 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading