Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarter watch #5642

Open
jgoux opened this issue Mar 2, 2021 · 2 comments
Open

Smarter watch #5642

jgoux opened this issue Mar 2, 2021 · 2 comments
Labels
core Related to codegen core/cli kind/enhancement New feature or request

Comments

@jgoux
Copy link

jgoux commented Mar 2, 2021

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

@dotansimha dotansimha added core Related to codegen core/cli enhancement labels Mar 7, 2021
@dotansimha
Copy link
Owner

Totally agree here. We try to watch specific files by default (without the watch defined), but allow to add additional files in case something is missing. The fact that we eventually aggregate all files into a single list might limit us. I totally agree that this could be improved.

@dotansimha dotansimha added kind/enhancement New feature or request and removed enhancement labels Jun 20, 2021
@saihaj saihaj added this to the CLI Improvements milestone Jun 29, 2022
@charlypoly
Copy link
Contributor

Note:
The way we currently check for file changes is not working if Prettier - or similar code formatter, making the watch mode obsolete.

Source: #2872 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants