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

fix: regeneration should only happen for config document pattern #9051

Conversation

saihaj
Copy link
Collaborator

@saihaj saihaj commented Feb 23, 2023

#9009 missed the fact that watch is running everywhere. Could not find a built in way with parcel but got a work around which I think is good enough for us.

closes #9045

Before

CleanShot.2023-02-23.at.13.28.35.mp4

After

CleanShot.2023-02-23.at.13.27.13.mp4

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2023

🦋 Changeset detected

Latest commit: 66a48bd

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 Patch
@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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2023

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-cli/codegen 3.0.3-alpha-20230223182325-66a48bd80 npm ↗︎ unpkg ↗︎
@graphql-codegen/cli 3.2.1-alpha-20230223182325-66a48bd80 npm ↗︎ unpkg ↗︎

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2023

🦋 Changeset detected

Latest commit: 254177b

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 Patch
@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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2023

🚀 Website Preview

The latest changes to the website are available as preview in: https://5f19b19c.graphql-code-generator.pages.dev

@saihaj saihaj merged commit f7313f7 into master Feb 23, 2023
@saihaj saihaj deleted the saihaj/9045-graphql-codegencli-320-watch-mode-regeneration-triggers-on-all-file-changes-not-just-files-specified-in-config-documents-pattern branch February 23, 2023 18:36
* @parcel/watcher has no way to run watcher on specific files (https://github.com/parcel-bundler/watcher/issues/42)
* But we can use micromatch to filter out events that we don't care about
*/
if (!mm.contains(path, files)) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saihaj I believe there's still an issue here when a negated path is used.

My use case looks like this:

documents:
  - './apps/frontend/src/app/**/*.graphql'
  - '!./apps/frontend/src/app/exclude-these/**/*.graphql'

I'm seeing the watcher run when any file in my source tree is changed, and I'm thinking it's due to '!./apps/frontend/src/app/exclude-these/**/*.graphql' causing the mm.contains call to return true.

Quick example with mm:

const mm = require('micromatch');

// Prints false
console.log(mm.contains('anyfile.js', './some-dir/**/*.graphql'));

// Prints true
console.log(mm.contains('anyfile.js', '!./some-dir/**/*.graphql'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked the code, but have noticed an excessive amount of runs in watch mode since the update myself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can open issue with repro will be easier for me to debug and fix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have downgraded to 3.1.0 and noticed that there is indeed a regression in newer versions causing the generator to run 5-10 times in a row (probably tracking changes in the .next folder). For now in 3.2+ I had to remove all negated paths and be more specific with included directories which helped to reduce the amount of compilations.

Unfortunantely my project is not public and I don't necesarily have sufficient time to reduce it to a MWE, but I could consider sharing the repository with you @saihaj in case you'd be willing to look into it unless somebody has a decent reproduction.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor update: I found the --debug flag and confirmed that having negations causes them to be picked up causing the excess updates:
CleanShot 2023-03-11 at 16 46 27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a similar investigation by using --debug and modifying the source directly and can confirm the same thing that Christian is seeing. I was able to remove the negated pattern and now things work as I want them do.

Fortunately, our project doesn't need the negated pattern - I only added the negated pattern with v3.2.0 to try to fix the issue that this PR ended up fixing. I am sharing this to confirm the behavior that the other user is also seeing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great find! Let's use this cause this PR notif got hidden in my inbox #9177

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the exact same issue in our Next app, now tracking it here #9270 (instead of #9177)

Think I found the issue/root cause, working on a fix now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants