Skip to content

Commit ceb9fe0

Browse files
authoredSep 30, 2020
Add watch polling configuration (#4823)
* Add watch polling configuration - Change usePolling default from `true` to `false` - add `watchPolling` config file option to configure polling * Update watch config structure * Include changeset message
1 parent 1422ab1 commit ceb9fe0

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed
 

‎.changeset/funny-bikes-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': minor
3+
---
4+
5+
Changes watch mode to not use polling by default and adds configurable override

‎packages/graphql-codegen-cli/src/utils/watcher.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function emitWatching() {
2424
export const createWatcher = (
2525
initalContext: CodegenContext,
2626
onNext: (result: Types.FileOutput[]) => Promise<Types.FileOutput[]>
27-
) => {
27+
): Promise<void> => {
2828
debugLog(`[Watcher] Starting watcher...`);
2929
let config: Types.Config & { configFilePath?: string } = initalContext.getConfig();
3030
const files: string[] = [initalContext.filepath].filter(a => a);
@@ -94,9 +94,8 @@ export const createWatcher = (
9494
followSymlinks: true,
9595
cwd: process.cwd(),
9696
disableGlobbing: false,
97-
usePolling: true,
98-
interval: 100,
99-
binaryInterval: 300,
97+
usePolling: config.watchConfig?.usePolling,
98+
interval: config.watchConfig?.interval,
10099
depth: 99,
101100
awaitWriteFinish: true,
102101
ignorePermissionErrors: false,
@@ -141,7 +140,7 @@ export const createWatcher = (
141140
};
142141

143142
// the promise never resolves to keep process running
144-
return new Promise((resolve, reject) => {
143+
return new Promise<void>((resolve, reject) => {
145144
executeCodegen(initalContext)
146145
.then(onNext, () => Promise.resolve())
147146
.then(runWatcher)

‎packages/utils/plugins-helpers/src/types.ts

+11
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ export namespace Types {
414414
* For more details: https://graphql-code-generator.com/docs/getting-started/development-workflow#watch-mode
415415
*/
416416
watch?: boolean | string | string[];
417+
/**
418+
* @description Allows overriding the behavior of watch to use stat polling over native file watching support.
419+
*
420+
* Config fields have the same defaults and sematics as the identically named ones for chokidar.
421+
*
422+
* For more details: https://graphql-code-generator.com/docs/getting-started/development-workflow#watch-mode
423+
*/
424+
watchConfig?: {
425+
usePolling: boolean;
426+
interval?: number;
427+
};
417428
/**
418429
* @description A flag to suppress printing errors when they occur.
419430
*/

‎website/docs/getting-started/development-workflow.md

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ If you wish, you can specify a custom list of files to watch, by adding a glob e
5050
Use this when you are loading your schema or documents from a single code file, that depends on other files internally, because codegen can't tell that you using those files automatically.
5151
:::
5252

53+
By default, watch mode uses the system's native support to listen for file change events. This can be configured in the settings file to use a stat polling method instead in unusual cases where system support is unavailable.
54+
55+
```yml
56+
watch: true
57+
# Passed directly through to chokidar's file watch configuration
58+
watchConfig:
59+
usePolling: true
60+
interval: 1000
61+
```
62+
63+
5364
### Monorepo and Yarn Workspaces
5465
5566
If you are using a monorepo structure, with tools such as [Yarn Workspaces](https://yarnpkg.com/lang/en/docs/workspaces/) or [Lerna](https://github.com/lerna/lerna), we recommend to install the codegen in the root of your monorepo.

0 commit comments

Comments
 (0)
Please sign in to comment.