apollographql / apollographql/apollo-tooling
Codegen in --watch mode doesn't handle deletions/renames fully
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
**Intended outcome:**
`--watch` is able to track added, deleted and renamed files.
**Actual outcome:**
Currently only changes in preexisting files trigger watch.
**How to reproduce the issue:**
Try to create a query file matching `includes` pattern.
**Further info:**
There are two parts to this problem:
1. Watching logic is insufficient (no deletion and rename handling at least):
https://github.com/apollographql/apollo-tooling/blob/a30f0e16b0dc65a7e09cb2c2c1a87a8962de2654/packages/apollo/src/commands/client/codegen.ts#L219
2. Even after quick fix I made locally to handle specific cases:
```
...
watcher.on("changed", (file) => {
console.log('Watch event: changed', file);
this.project.fileDidChange(vscode_uri_1.default.file(file).toString());
});
watcher.on("deleted", (file) => {
console.log('Watch event: deleted', file);
this.project.fileWasDeleted(vscode_uri_1.default.file(file).toString());
});
watcher.on("added", (file) => {
console.log('Watch event: added', file);
this.project.fileDidChange(vscode_uri_1.default.file(file).toString());
});
watcher.on("renamed", (file, newFile) => {
console.log('Watch event: renamed', file);
this.project.fileWasDeleted(vscode_uri_1.default.file(file).toString());
this.project.fileDidChange(vscode_uri_1.default.file(newFile).toString());
});
...
```
the result is not satisfactory. For example deletion of enclosing folder doesn't trigger file deletion. Gaze lib used for watching seems [quite unreliable in edge-cases](https://github.com/shama/gaze/issues).
Also it doesn't handle globs with relative paths (`--includes './src/**/*.gql'`).
Contributor guide
Research direction
Start in packages/apollo/src/commands/client/codegen.ts around the watcher logic linked in the issue, then inspect how Gaze reports file events. Reproduce with an added query matching the includes pattern, deletion or renaming, enclosing-folder deletion, and a relative glob such as ./src/**/*.gql. Done means --watch reliably handles additions, deletions, renames, and relative-path globs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100