From dce40edebe4ffa0f0533f2728b278ee06eeff09d Mon Sep 17 00:00:00 2001 From: Rohit Gohri Date: Wed, 6 Jul 2022 01:55:19 +0530 Subject: [PATCH] Allow disabling watch from cli (#7781) * Allow disabling watch from cli * add tests * add changeset Co-authored-by: Saihajpreet Singh --- .changeset/serious-needles-impress.md | 9 +++++++++ packages/graphql-codegen-cli/src/config.ts | 2 +- .../graphql-codegen-cli/tests/cli-flags.spec.ts | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/serious-needles-impress.md 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