Skip to content

Commit

Permalink
Allow disabling watch from cli (#7781)
Browse files Browse the repository at this point in the history
* Allow disabling watch from cli

* add tests

* add changeset

Co-authored-by: Saihajpreet Singh <saihajpreet.singh@gmail.com>
  • Loading branch information
rohit-gohri and saihaj committed Jul 5, 2022
1 parent e7870ac commit dce40ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .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
```
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/src/config.ts
Expand Up @@ -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;
}

Expand Down
16 changes: 15 additions & 1 deletion packages/graphql-codegen-cli/tests/cli-flags.spec.ts
Expand Up @@ -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
Expand All @@ -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
Expand Down

1 comment on commit dce40ed

@vercel
Copy link

@vercel vercel bot commented on dce40ed Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.