diff --git a/.changeset/serious-needles-impress.md b/.changeset/serious-needles-impress.md new file mode 100644 index 00000000000..4a80e9c70b2 --- /dev/null +++ b/.changeset/serious-needles-impress.md @@ -0,0 +1,9 @@ +--- +'@graphql-codegen/cli': patch +--- + +Allow to disable watch mode from CLI to overwrite the config. Now you can do: + +```bash +$ graphql-codegen --watch=false +``` diff --git a/packages/graphql-codegen-cli/src/config.ts b/packages/graphql-codegen-cli/src/config.ts index f6e6d31a068..a03c9c66767 100644 --- a/packages/graphql-codegen-cli/src/config.ts +++ b/packages/graphql-codegen-cli/src/config.ts @@ -265,7 +265,7 @@ export function updateContextWithCliFlags(context: CodegenContext, cliFlags: Yam configFilePath: context.filepath, }; - if (cliFlags.watch) { + if (cliFlags.watch !== undefined) { config.watch = cliFlags.watch; } diff --git a/packages/graphql-codegen-cli/tests/cli-flags.spec.ts b/packages/graphql-codegen-cli/tests/cli-flags.spec.ts index 64f444005ac..51f53ebfed6 100644 --- a/packages/graphql-codegen-cli/tests/cli-flags.spec.ts +++ b/packages/graphql-codegen-cli/tests/cli-flags.spec.ts @@ -92,7 +92,7 @@ describe('CLI Flags', () => { expect(config.overwrite).not.toBeTruthy(); }); - it('Should overwrite watch config using cli flags', async () => { + it('Should overwrite watch config using cli flag to true', async () => { mockConfig(` schema: schema.graphql watch: false @@ -106,6 +106,20 @@ describe('CLI Flags', () => { expect(config.watch).toBeTruthy(); }); + it('Should overwrite watch config using cli flags to false', async () => { + mockConfig(` + schema: schema.graphql + watch: true + generates: + file.ts: + - plugin + `); + const args = createArgv('--watch=false'); + const context = await createContext(parseArgv(args)); + const config = context.getConfig(); + expect(config.watch).toBeFalsy(); + }); + it('Should set --overwrite with new YML api', async () => { mockConfig(` schema: schema.graphql