graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Implemented first generation skip in watch mode.

Open cbmd opened this issue 4 years ago • 6 comments

Description

Implemented possibility to skip first generation whenever some pre-script previously can already generate files which result onto unnecessary re-generation on cold start of scripts. With this change it's no longer necessary.

Related # (issue)

Type of change

Please delete options that are not relevant.

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [x] Changed over config values and then manually trigger watcher
  • [x] Added watchSkipFirst CLI flag and then manually trigger watcher

Checklist:

  • [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

cbmd avatar Jun 17 '21 08:06 cbmd

🦋 Changeset detected

Latest commit: fcc8579aa30ab32e2ba88667f4ed281f4c7f268e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/cli Minor
@graphql-cli/codegen Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jun 17 '21 08:06 changeset-bot[bot]

Thank you for creating this PR, @cbmd ! Can you please explain the background and use-case for this? I'm not sure that I understood it.

dotansimha avatar Jun 20 '21 08:06 dotansimha

Sure @dotansimha, use case if following: You wanted to run watch more of codegen AND webpack build simultaneously, whiles it's possible when you have some files already generated it's impossible on "fresh install" (due to both processes start at a same time). So what I'm suggesting is to skip mandatory first compilation and have granular control over it. E.g.

{
  "scripts": {
    "prestart": "graphql-codegen",
    "start": "graphql-codegen --watch --skipFirst & webpack"
  }
}

And in this case it would still success to compile with webpack (Cuz all files already be in place while it would be boostraped) and will have re-compilation (cuz codegen would re-create files and then would trigger watcher of webpack, or any other bundler in place) of app.

And in this case I would not need to regenerate same things twice.

cbmd avatar Jun 22 '21 19:06 cbmd

I see, thank you @cbmd for explaining! I can merge that but may be worth checking with @piglovesyou since he's doing some cool stuff with codegen and Webpack in https://github.com/piglovesyou/graphql-let , so maybe its something that can be beneficial as well?

Also, in most implementations of codegen and Webpack, the programmatic API is used, and then you can control when and how to call codegen.

dotansimha avatar Jun 29 '21 13:06 dotansimha

fwiw I would really enjoy this feature. We currently commit our generated files so it is only necessary to regen when graphql documents or schema changes.

coreylight avatar Sep 15 '21 16:09 coreylight

Hi @cbmd!

Do you still plan to work on this PR? 👀

charlypoly avatar Feb 10 '22 14:02 charlypoly