Skip to content

Smarter watch #5642

Open
Open
@jgoux

Description

@jgoux

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreRelated to codegen core/clikind/enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions