Skip to content

Bugfix: enums from external fragments were not generated along with operations#10565

Merged
eddeee888 merged 36 commits intodotansimha:master-nextfrom
ikusakov2:feature/add-config-extractAllFieldsToTypesCompact
Jan 19, 2026
Merged

Bugfix: enums from external fragments were not generated along with operations#10565
eddeee888 merged 36 commits intodotansimha:master-nextfrom
ikusakov2:feature/add-config-extractAllFieldsToTypesCompact

Conversation

@ikusakov2
Copy link
Contributor

@ikusakov2 ikusakov2 commented Jan 7, 2026

Description

This PR includes 2 fixes:

  1. enums from external fragment were not copied to the generated file along with operations.
  2. extractAllFieldsToTypesCompact config option in certain conditions generate duplicate names

Additionally, an integration test is added that mimics the Apollo-tooling setup:
dev-test-apollo-tooling

Testing

  • Unit tests

@ikusakov2 ikusakov2 changed the title An intergration test showing errors with recent alpha version An integration test showing errors with recent alpha version Jan 7, 2026
@ikusakov2 ikusakov2 changed the base branch from master to master-next January 7, 2026 20:27
@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 180a80a

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

This PR includes changesets to release 9 packages
Name Type
@graphql-codegen/typescript-operations Minor
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/client-preset 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

@ikusakov2 ikusakov2 marked this pull request as ready for review January 7, 2026 22:03
Comment on lines +125 to +128
const documentWithExternalFragments: DocumentNode = {
...documentNode,
definitions: [...documentNode.definitions, ...(config.externalFragments || []).map(f => f.node)],
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if the functionality in the above statement used to create allFragments could be used for our fragments here somehow? 🤔
It seems to do a similar function of collecting fragments, either from documents or from config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call!
Check the new code - I combined it with allFragments.

@@ -0,0 +1,2 @@
**/__generated__/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel we should unignore the generation 🙂
This could be a good test that can be kept as snapshot test, and an advanced use case of codegen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, generated files added!

@@ -0,0 +1,106 @@
#!/usr/bin/env ts-node
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created the dev-test-alpha just as a temporary package to demonstrate our company issues.
Do you think it would be worth keeping it?
Then:

  • I'll need to add some tests which would get invoked when global tests are running.
  • We need to come up with some better name than dev-test-alpha

Copy link
Collaborator

@eddeee888 eddeee888 Jan 11, 2026

Choose a reason for hiding this comment

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

Yes, I think so! I find this test is very valuable, as it can be used to catch unexpected bugs, at least in the initial stage after rolling out.

I feel we might be able to simplify a few things in the setup. And worst case, if its usefulness is overshadowed by maintenance, we can decide to drop it (or further simplify) later 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I renamed dev-test-alpha to dev-test-apollo-tooling - to give a more descriptive name to what this integration test it about. I also added another (hopefully last) fix - so you can run yarn install && yarn build from the root directory: graphql-code-generator and - it should work.

// @generated
// This file was automatically generated and should not be edited.

import type * as Types from '../../graphql-code-generator/dev-test-alpha/src/__generated__/globalTypes';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we already worked on removing this line in typescript-operations plugin.
But it probably comes from near-operation-file preset.
Shall we ignore it until we do the next version of near-operation-file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a research and - yes, it comes from near-operation-file.


type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
export enum UserManagerRoleType {
Copy link
Contributor Author

@ikusakov2 ikusakov2 Jan 8, 2026

Choose a reason for hiding this comment

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

With the recent fix - it adds the enum in the correct file.

@ikusakov2 ikusakov2 closed this Jan 8, 2026
@ikusakov2 ikusakov2 deleted the feature/add-config-extractAllFieldsToTypesCompact branch January 8, 2026 23:00
@ikusakov2 ikusakov2 restored the feature/add-config-extractAllFieldsToTypesCompact branch January 8, 2026 23:02
@ikusakov2 ikusakov2 reopened this Jan 8, 2026
@ikusakov2 ikusakov2 changed the title An integration test showing errors with recent alpha version Fixing an issue with including enums from external fragments Jan 12, 2026
@ikusakov2 ikusakov2 changed the title Fixing an issue with including enums from external fragments Bugfix: enums from external fragments were not generated along with operations Jan 12, 2026
Copy link
Collaborator

@eddeee888 eddeee888 Jan 19, 2026

Choose a reason for hiding this comment

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

Image

👆 The previous commit had package issues because there were lots of changes (+4k -2k LOC changes) in yarn.lock, which I think caused some package versions to be conflicting.

I've fixed this issue in this commit

git checkout b55828d4ea802db1476fb7eaada41592b9c80985 -- yarn.lock // get working yarn.lock of a stable commit
yarn // re-install packages whilst checking that minimal line changes happened and tests can run

Copy link
Collaborator

@eddeee888 eddeee888 left a comment

Choose a reason for hiding this comment

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

Nice one!

@eddeee888 eddeee888 merged commit b51daba into dotansimha:master-next Jan 19, 2026
19 checks passed
eddeee888 added a commit that referenced this pull request Jan 20, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Feb 25, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 3, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
ikusakov2 added a commit to ikusakov2/graphql-code-generator that referenced this pull request Mar 4, 2026
…perations (dotansimha#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 8, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 8, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 8, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 12, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
eddeee888 added a commit that referenced this pull request Mar 19, 2026
…perations (#10565)

* integration test

* cleanups

* cleanups2

* fixed a bug with external fragments

* cleanup

* keep generated files, refactored visitorwq

* cleanup

* changeset

* adding missing dependency

* delete temporary files

* cleanup

* cleanups

* Adding back the integration tests + fix them

* merged + fixes

* cleanup

* cleanup

* patching near-operation-file preset

* cleanup

* adding duplicates case to integration tests

* Fixing bug with duplicates generated when using extractAllFieldsToTypesCompact

* cleanup

* prevent running prettier on generated code

* cleanups

* cleanup

* adding unit tests

* update changeset

* cleanups

* try resolving graphql 16 error

* remove unused deps

* remove unused deps

* cleanups

* Revert and apply minimal yarn.lock changes

---------

Co-authored-by: ikusakov <ikusakov@gxnfgqk426.y.yelp>
Co-authored-by: Igor Kusakov <igor@kusakov.com>
Co-authored-by: Eddy Nguyen <github@eddeee888.me>
Co-authored-by: Eddy Nguyen <ch@eddeee888.me>
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.

3 participants