apollographql / apollographql/apollo-tooling

Codegen watcher crashes when file is deleted or renamed

Open
#2,196 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

**Intended outcome:**

When using `apollo client:codegen --watch` I expect that it can handle file deletes and renames.

**Actual outcome:**

The watcher crashes:
```
Error: ENOENT: no such file or directory, lstat 'f:\workspace\project\src\components\ComponentWithQuery.tsx'
at Object.lstatSync (fs.js:917:3)
at GraphQLClientProject.fileDidChange (F:\workspace\project\node_modules\apollo-language-server\lib\project\base.js:101:19)
at Gaze. (F:\workspace\project\node_modules\apollo\lib\commands\client\codegen.js:118:30)
at Gaze.emit (events.js:210:5)
at Gaze.emit (F:\workspace\project\node_modules\gaze\lib\gaze.js:129:32)
at F:\workspace\project\node_modules\gaze\lib\gaze.js:418:18
at Array.forEach ()
at F:\workspace\project\node_modules\gaze\lib\gaze.js:414:12
at FSReqCallback.oncomplete (fs.js:157:23) {
errno: -4058,
syscall: 'lstat',
code: 'ENOENT',
path: 'f:\\workspace\\project\\src\\components\\ComponentWithQuery.tsx'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

**How to reproduce the issue:**

1. Create a file with a gql statement.
2. Start a watcher with `apollo client:codegen --watch`.
3. Rename the file you created in the first step.

**Versions**

Probably all, but specifically **2.31.0**

---

When applying a workaround for this issue, for instance by guarding the call to `lstatSync`, the watcher will still crash, but for a different reason. There is already a ticket for this issue here: https://github.com/apollographql/apollo-tooling/issues/1920

Contributor guide

Open the contributing guide

Research direction

Start with the watcher entry point in apollo/lib/commands/client/codegen.js and the fileDidChange path in apollo-language-server/lib/project/base.js, using the reported rename reproduction. Check the related issue #1920 before proceeding; done means `apollo client:codegen --watch` remains running when a watched file is deleted or renamed.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, node.js, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.