apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

Codegen in --watch mode doesn't handle deletions/renames fully #873

Open brabeji opened 5 years ago

brabeji commented 5 years ago

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. Also it doesn't handle globs with relative paths (--includes './src/**/*.gql').

JakeDawkins commented 5 years ago

We're working on trying out @atom/watcher watcher right now to support larger codebases. If we find it's performant enough, I'll take a look at adding in handlers for deletion and renames.

That may be tough though, since deleting/renaming files containing types could be an issue. I'll mention more later on if we move forward.

Also it doesn't handle globs with relative paths (--includes './src/**/*.gql').

this will be fixed with the release of #1007