Skip to content

Commit

Permalink
Config file options should override the CLI defaults (#7518)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
enisdenjo and github-actions[bot] committed Aug 15, 2024
1 parent 7ac0376 commit b0cdc83
Show file tree
Hide file tree
Showing 37 changed files with 227 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_fusion-runtime-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/fusion-runtime": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_grpc-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/grpc": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/hmac-upstream-signature": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_json-schema-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/json-schema": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/json-schema@0.105.1` ↗︎](https://www.npmjs.com/package/@omnigraph/json-schema/v/0.105.1) (from `0.105.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_mysql-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/mysql": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/mysql@^0.6.1` ↗︎](https://www.npmjs.com/package/@omnigraph/mysql/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_neo4j-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/neo4j": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/neo4j@^0.6.1` ↗︎](https://www.npmjs.com/package/@omnigraph/neo4j/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_openapi-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/openapi": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/openapi@0.105.1` ↗︎](https://www.npmjs.com/package/@omnigraph/openapi/v/0.105.1) (from `0.105.0`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/plugin-opentelemetry": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/plugin-operation-headers": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/serve-runtime@^0.7.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/serve-runtime/v/0.7.1) (from `^0.7.0`, in `peerDependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/plugin-prometheus": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/serve-runtime@^0.7.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/serve-runtime/v/0.7.1) (from `^0.7.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_raml-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/raml": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/raml@0.105.1` ↗︎](https://www.npmjs.com/package/@omnigraph/raml/v/0.105.1) (from `0.105.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_serve-cli-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/serve-cli": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/serve-runtime@^0.7.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/serve-runtime/v/0.7.1) (from `^0.7.0`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_serve-runtime-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/serve-runtime": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/fusion-runtime@^0.7.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/fusion-runtime/v/0.7.1) (from `^0.7.0`, in `dependencies`)
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
- Updated dependency [`@graphql-mesh/transport-http@^0.5.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-http/v/0.5.1) (from `^0.5.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_soap-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/soap": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/soap@0.103.1` ↗︎](https://www.npmjs.com/package/@omnigraph/soap/v/0.103.1) (from `0.103.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_thrift-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/thrift": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/thrift@^0.6.1` ↗︎](https://www.npmjs.com/package/@omnigraph/thrift/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-http-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-http": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-http-callback": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-mysql-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-mysql": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-neo4j-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-neo4j": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-rest-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-rest": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `peerDependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-soap-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-soap": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `peerDependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-sqlite": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-thrift": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_transport-ws-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/transport-ws": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
6 changes: 6 additions & 0 deletions .changeset/@omnigraph_json-schema-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@omnigraph/json-schema": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1) (from `^0.6.0`, in `dependencies`)
- Updated dependency [`@graphql-mesh/transport-rest@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-rest/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_mysql-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/mysql": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-mysql@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-mysql/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_neo4j-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/neo4j": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-neo4j@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-neo4j/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_openapi-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/openapi": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/json-schema@^0.105.1` ↗︎](https://www.npmjs.com/package/@omnigraph/json-schema/v/0.105.1) (from `^0.105.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_raml-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/raml": patch
---
dependencies updates:
- Updated dependency [`@omnigraph/json-schema@0.105.1` ↗︎](https://www.npmjs.com/package/@omnigraph/json-schema/v/0.105.1) (from `0.105.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_soap-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/soap": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-soap@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-soap/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@omnigraph_thrift-7518-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnigraph/thrift": patch
---
dependencies updates:
- Updated dependency [`@graphql-mesh/transport-thrift@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-thrift/v/0.6.1) (from `^0.6.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/plenty-feet-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/serve-cli': patch
---

Config file options should override the CLI defaults
39 changes: 22 additions & 17 deletions packages/serve-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import 'json-bigint-patch'; // JSON.parse/stringify with bigints support
import cluster from 'node:cluster';
import { availableParallelism, release } from 'node:os';
import parseDuration from 'parse-duration';
import {
Command,
InvalidArgumentError,
Option,
type OptionValues,
} from '@commander-js/extra-typings';
import { Command, InvalidArgumentError, Option } from '@commander-js/extra-typings';
import type {
MeshServeConfigProxy,
MeshServeConfigSubgraph,
Expand Down Expand Up @@ -97,12 +92,19 @@ export interface CLIContext {
/** Inferred program options from the root command {@link cli}. */
export type CLIGlobals = CLI extends Command<any, infer O> ? O : never;

export const defaultFork = process.env.NODE_ENV === 'production' ? availableParallelism() : 1;

export type CLI = typeof cli;

export type AddCommand = (ctx: CLIContext, cli: CLI) => void;

// we dont use `Option.default()` in the command definitions because we want the CLI options to
// override the config file (with option defaults, config file will always be overwritten)
export const defaultOptions = {
fork: process.env.NODE_ENV === 'production' ? availableParallelism() : 1,
host: release().toLowerCase().includes('microsoft') ? '127.0.0.1' : '0.0.0.0',
port: 4000,
polling: '10s',
};

/** The root cli of serve-cli. */
let cli = new Command()
.configureHelp({
Expand All @@ -112,7 +114,7 @@ let cli = new Command()
.addOption(
new Option(
'--fork <count>',
'count of workers to spawn. defaults to `os.availableParallelism()` when NODE_ENV is "production", otherwise only one (the main) worker',
`count of workers to spawn. defaults to "os.availableParallelism()" when NODE_ENV is "production", otherwise only one (the main) worker (default: ${JSON.stringify(defaultOptions.fork)}`,
)
.env('FORK')
.argParser(v => {
Expand All @@ -121,8 +123,7 @@ let cli = new Command()
throw new InvalidArgumentError('not a number.');
}
return count;
})
.default(defaultFork),
}),
)
.addOption(
new Option(
Expand All @@ -132,13 +133,15 @@ let cli = new Command()
)
.option(
'-h, --host <hostname>',
'host to use for serving',
release().toLowerCase().includes('microsoft') ? '127.0.0.1' : '0.0.0.0',
`host to use for serving (default: ${JSON.stringify(defaultOptions.host)}`,
defaultOptions.host,
)
.addOption(
new Option('-p, --port <number>', 'port to use for serving')
new Option(
'-p, --port <number>',
`port to use for serving (default: ${JSON.stringify(defaultOptions.port)}`,
)
.env('PORT')
.default(4000)
.argParser(v => {
const port = parseInt(v);
if (isNaN(port)) {
Expand All @@ -148,9 +151,11 @@ let cli = new Command()
}),
)
.addOption(
new Option('--polling <duration>', 'schema polling interval in human readable duration')
new Option(
'--polling <duration>',
`schema polling interval in human readable duration (default: ${JSON.stringify(defaultOptions.polling)})`,
)
.env('POLLING')
.default(10_000, '10s')
.argParser(v => {
const interval = parseDuration(v);
if (!interval) {
Expand Down
9 changes: 8 additions & 1 deletion packages/serve-cli/src/commands/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import cluster, { type Worker } from 'node:cluster';
import { Option } from '@commander-js/extra-typings';
import { createServeRuntime, type MeshServeConfigProxy } from '@graphql-mesh/serve-runtime';
import { registerTerminateHandler } from '@graphql-mesh/utils';
import type { AddCommand, CLIContext, CLIGlobals, MeshServeCLIConfig } from '../cli.js';
import {
defaultOptions,
type AddCommand,
type CLIContext,
type CLIGlobals,
type MeshServeCLIConfig,
} from '../cli.js';
import { loadConfig } from '../config.js';
import { startServerForRuntime } from '../server.js';

Expand Down Expand Up @@ -68,6 +74,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
}

const config: ProxyConfig = {
...defaultOptions,
...loadedConfig,
...opts,
...(hiveRegistryToken
Expand Down
9 changes: 8 additions & 1 deletion packages/serve-cli/src/commands/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
} from '@graphql-mesh/serve-runtime';
import { isUrl, registerTerminateHandler } from '@graphql-mesh/utils';
import { isValidPath } from '@graphql-tools/utils';
import type { AddCommand, CLIContext, CLIGlobals, MeshServeCLIConfig } from '../cli.js';
import {
defaultOptions,
type AddCommand,
type CLIContext,
type CLIGlobals,
type MeshServeCLIConfig,
} from '../cli.js';
import { loadConfig } from '../config.js';
import { startServerForRuntime } from '../server.js';

Expand Down Expand Up @@ -40,6 +46,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
}

const config: SubgraphConfig = {
...defaultOptions,
...loadedConfig,
...opts,
...(hiveRegistryToken
Expand Down
9 changes: 8 additions & 1 deletion packages/serve-cli/src/commands/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
} from '@graphql-mesh/serve-runtime';
import { isUrl, registerTerminateHandler } from '@graphql-mesh/utils';
import { isValidPath } from '@graphql-tools/utils';
import type { AddCommand, CLIContext, CLIGlobals, MeshServeCLIConfig } from '../cli.js';
import {
defaultOptions,
type AddCommand,
type CLIContext,
type CLIGlobals,
type MeshServeCLIConfig,
} from '../cli.js';
import { loadConfig } from '../config.js';
import { startServerForRuntime } from '../server.js';

Expand Down Expand Up @@ -51,6 +57,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
}

const config: SupergraphConfig = {
...defaultOptions,
...loadedConfig,
...opts,
...(hiveRegistryToken
Expand Down
Loading

0 comments on commit b0cdc83

Please sign in to comment.