Intended outcome:
When using apollo client:codegen --watch, I expect that I can "set and it and forget it" to watch files, attempt to generate code for any new or changed gql, and try again after a file changes if it encounters any fatal errors in the last run.
Actual outcome:
When writing code, sometimes there are typos or compilation errors that cause apollo client:codegen --watch to crash completely, meaning that it is no longer watching any files. This typically happens after changing the name of a query within gql or copying gql from one place to another.
It's frustrating because I don't keep the watcher up all the time, and I only notice when I don't get new generated types even after all the code is correct again. It happens so often that I end up having to babysit it, which means that I may as well just run apollo client:codegen without --watch every time I feel like the code is in a good place.
The following is just one example of the type of error that causes a crash, but I'm guessing there are a class of errors like this one that are not caught by the watch loop.
some-project/node_modules/apollo-language-server/lib/project/base.js:126
throw new Error(`锔忥笍There are multiple definitions for the \`${definition.name.value}\` operation. Please rename or remove all operations with the duplicated name before continuing.`);
^
Error: 锔忥笍There are multiple definitions for the `SomeQuery` operation. Please rename or remove all operations with the duplicated name before continuing.
at GraphQLClientProject.checkForDuplicateOperations (some-project/node_modules/apollo-language-server/lib/project/base.js:126:31)
at GraphQLClientProject.documentDidChange (some-project/node_modules/apollo-language-server/lib/project/base.js:116:14)
at GraphQLClientProject.fileDidChange (some-project/node_modules/apollo-language-server/lib/project/base.js:101:14)
at Gaze.<anonymous> (some-project/node_modules/apollo/lib/commands/client/codegen.js:112:30)
at Gaze.emit (events.js:311:20)
at Gaze.emit (some-project/node_modules/gaze/lib/gaze.js:129:32)
at Gaze.<anonymous> (some-project/node_modules/gaze/lib/gaze.js:430:18)
at Timeout._onTimeout (some-project/node_modules/gaze/lib/gaze.js:458:24)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] apollo-codegen:watch: `apollo client:codegen --target typescript --watch`
Process finished with exit code 1
How to reproduce the issue:
gql query and use it in a componentclient:codegen --watch crashes with error aboveclient:codegen --watch should catch any errors and be ready for the next file to changeVersions
"apollo": "2.27.3"
Similar to this the Apollo VSCode plugin crashes regularly due to this same exact error, and it's mostly silent. You can't even restart it without reloading the entire window because it gets rebooted in the background 5 times (crashing each time) and then VSCode gives up and stops trying to run it.
Most helpful comment
Similar to this the Apollo VSCode plugin crashes regularly due to this same exact error, and it's mostly silent. You can't even restart it without reloading the entire window because it gets rebooted in the background 5 times (crashing each time) and then VSCode gives up and stops trying to run it.