Skip to content

CODEGEN-834 - [cli] Handle partial generation success #10376

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

Open
wants to merge 7 commits into
base: federation-fixes
Choose a base branch
from

Conversation

eddeee888
Copy link
Collaborator

@eddeee888 eddeee888 commented Jun 27, 2025

Description

Introduce allowPartialOutputs to allow users to write partial success to files.

This is a breaking change because we change how executeCodegen function works (exposed and can be imported): previously if any generates fails, it'd throw. Now, it will return the error and output files as result and let the caller decide what to do with them.

The main caller of executeCodegen is the CLI and it (1.) throws if there is complete failure or (2) use allowPartialOutputs to write on partial success or not

Related #9701

Type of change

  • Breaking change

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

  • Unit test

Copy link

changeset-bot bot commented Jun 27, 2025

🦋 Changeset detected

Latest commit: 90126ec

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/plugin-helpers Minor
@graphql-codegen/cli Major

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

@eddeee888 eddeee888 force-pushed the handle-partial-error branch 2 times, most recently from c000be1 to 9c57b83 Compare June 27, 2025 11:50
Copy link
Contributor

github-actions bot commented Jun 27, 2025

🚀 Snapshot Release (alpha)

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

Package Version Info
@graphql-codegen/cli 6.0.0-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/core 4.0.3-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/add 5.0.4-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/fragment-matcher 5.1.1-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/introspection 4.0.4-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/schema-ast 4.1.1-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/time 5.0.2-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/visitor-plugin-common 6.0.0-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 4.0.17-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/gql-tag-operations 4.0.18-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 4.6.2-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-resolvers 5.0.0-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 5.1.3-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 4.1.7-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 4.8.4-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 4.0.18-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/testing 3.0.5-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎
@graphql-codegen/plugin-helpers 6.0.0-alpha-20250702094259-330e4c0c023358d9861caa216bc6e850fd799b01 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Jun 27, 2025

💻 Website Preview

The latest changes are available as preview in: https://pr-10376.graphql-code-generator.pages.dev

@eddeee888 eddeee888 changed the title Handle partial error Handle partial generation success Jul 1, 2025
@eddeee888 eddeee888 force-pushed the handle-partial-error branch from c0ce057 to 330e4c0 Compare July 2, 2025 09:41
@eddeee888 eddeee888 changed the base branch from master to federation-fixes July 2, 2025 09:41
@eddeee888 eddeee888 changed the title Handle partial generation success [cli] Handle partial generation success Jul 2, 2025
@@ -78,7 +78,10 @@ export const createWatcher = (
const debouncedExec = debounce(() => {
if (!isShutdown) {
executeCodegen(initialContext)
.then(onNext, () => Promise.resolve())
.then(
({ result }) => onNext(result),
Copy link
Collaborator Author

@eddeee888 eddeee888 Jul 2, 2025

Choose a reason for hiding this comment

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

Previously, partial success in watch mode doesn't write to files.

With this new no-throw-on-error implementation in watch mode, partial success always write to files.

Users primarily use watch mode only during development, so I think this is fine. They are already seeing something like "✔ Generate to ./src/graphql/types.generated.ts", which can be interpreted as something has been generated (check image below)

Screenshot 2025-07-04 at 12 13 36 am

@eddeee888 eddeee888 marked this pull request as ready for review July 3, 2025 14:21
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had an issue and thought running the command to update this would help 🤔
I think this file is only updated at build time before publishing the website. Maybe we don't have to track it?

Anyways, this should keep it up-to-date until we decide to ignore it (or not)

@@ -40,7 +40,7 @@ export default config

## Configuration options

Here are the supported options that you can define in the config file (see [source code](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/utils/plugins-helpers/src/types.ts#L92)):
Here are the supported options that you can define in the config file (see [source code](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/utils/plugins-helpers/src/types.ts#L388)):
Copy link
Collaborator Author

@eddeee888 eddeee888 Jul 3, 2025

Choose a reason for hiding this comment

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

I noticed the line number changed on master, so this updates it to point to the right Config type

@eddeee888 eddeee888 requested a review from dotansimha July 4, 2025 11:01
@eddeee888 eddeee888 changed the title [cli] Handle partial generation success CODEGEN-834 - [cli] Handle partial generation success Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant