dotansimha / dotansimha/graphql-code-generator

Smarter watch

Open
#5,642 4 comments 1 reaction 0 assignees View on GitHub
core kind/enhancement
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

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.
```yaml
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 :

```json
{
"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**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.