vite-plugin-graphql-codegen
vite-plugin-graphql-codegen copied to clipboard
chore: rewrite file watcher
Currently, file watcher asynchronously retrieves documents and schemas on each project file changes, which is slow, and caused unreasonably high resources usage.
Changes made
- resolve all configured documents and schemas only once on server startup and simply check file path matching in watcher.
- fix cases when schema path defined with dot like
./src/schema.graphqlby resolve absolute schema paths. - fix cases when documents defined with glob pattern like
./src/**/*.graphql, and modifyingsrc/path/api.graphql.generated.tsfile caused false positive check and trigger watcher for that file.
Also, this PR should resolve OOM issues reported in https://github.com/danielwaltz/vite-plugin-graphql-codegen/issues/27
Side changes
- reduce amount of log records, as currently it contains a lot of records which is not related to plugin: modifying any file in project produces ~5 log entries. Below are screenshots of the same number of interactions with project files demonstrating this.
Before
After
Thanks for your effort on these PRs! Hope to carve out the time in the next week or so to test them out and get them merged. 🎉
Thanks again for the work on this! I have implemented this strategy in a slightly different way that still supports the use cased of adding files. Please let me know if you run into any issues in the latest version!