Description
Is your feature request related to a problem? Please describe.
Currently when using the --watch
mode, every project/plugin is run, no matter the file that changed. I think it could be optimized.
Describe the solution you'd like
The most flexible solution would be to provide a watch
glob to each generates
block in the config so we can target specific files.
generates:
path/to/file.ts:
config:
avoidOptionals: true
plugins:
- typescript
- typescript-operations
watch: src/**/!(*.graphql).{ts,tsx}
I also think some plugin such as typescript-operations
could be optimized and exit early (and silently) if there was no change detected in the edited file. For example when I edit a file containing no graphql operation (so no gql-tag use) I expect the plugin to do nothing in watch mode. Right now it's regenerating all the operations.
So internally graphql-codegen would need to pass only the edited file to the plugin during watch mode.
Describe alternatives you've considered
Right now I'm doing it manually by splitting my configuration into multiple projects and using chokidar-cli
in my scripts :
{
"scripts": {
"graphql-codegen:dev": "concurrently \"yarn graphql-codegen:on-hasura-change\" \"yarn graphql-codegen:on-operations-change\" \"yarn graphql-codegen:on-schema-change\"",
"graphql-codegen:on-hasura-change": "chokidar \"packages/server/hasura/**/*\" --command \"graphql-codegen --project get-schema\" --silent",
"graphql-codegen:on-operations-change": "chokidar \"packages/client/src/**/!(*.graphql).{ts,tsx}\" --command \"graphql-codegen --project from-operations\" --silent",
"graphql-codegen:on-schema-change": "chokidar \"./schema.graphql\" --command \"graphql-codegen --project from-schema\" --silent",
}
}
Additional context