Skip to content

Conversation

@eddeee888
Copy link
Collaborator

Description

This PR re-adjusts a few config options that sits on different visitors incorrectly.

We have 4 main types of visitors:

  1. base-visitor: This is the parent visitor that the following 3 extend. Every config option here ideally should be usable to the other 3. An example i naming convention of types, so the other 3 can have a consistent way of referring to the same schema type if they need to be used together.
  2. documents-visitor: This is the visitor for client use cases e.g. operations.
  3. types-visitor: This is the visitor to generate schema types. Usable with resolvers-visitor
  4. resolvers-visitor: This is the visitor that uses the types from types-visitor for further extension

Note: documents-visitor includes base-documents-visitor and typscript-operations visitor. I've rolled these two up into one type here for simplicity

The updated config options are:

  • skipTypename (turned into addTypename internally): previously lives in the base-visitor. However, it is only a types-visitor concern. documents-visitor has its own way to enforce typename, and resolvers-visitor has its own .resolversTypename already.
    • This option has been moved from base-visitor to types-visitor
  • nonOptionalTypename: previously lives in the base-visitor. However, it is a documents-visitor and types-visitor concern.
    • Moved from base-visitor there.
  • extractAllFieldsToTypes: is a documents-visitor concern as it is only used to generate operation types
    • Moved from base-visitor to documents-visitor
  • enumPrefix and enumSuffix: need to be in base-visitor as all 3 types of visitors need this to correctly sync the enum type names.
    • Logic related to this is moved from 3 children to the base visitor
  • ignoreEnumValuesFromSchema: is a documents-visitor and types-visitor concern.
    • Moved from base-visitor there.
  • globalNamespace: is a documents-visitor concern.
    • Moved from base-visitor there

Other refactors:

  • documents-visitor no longer extends types-visitor option types as they have two distinct usages now. The types now extend base-visitor types. This is now consistent with documents-visitor extending base-visitor
  • Classes now handle config parsing and types at the same level
    • e.g. if typescript-operations plugin parses configOne, then the types for configOne must be in that class, rather than in base-documents-visitor

Related #10496

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Unit test

- addTypename/skipTypename: is only a types-visitor concern. This is moved to types-visitor from base-visitor
- nonOptionalTypename: is a documents-visitor and types-visitor concern. Moved from base-visitor there
- extractAllFieldsToTypes: is a documents-visitor concern. Moved from base-visitor there
- enumPrefix and enumSuffix: need to be in base-visitor as all 3 types of visitors need this to correctly sync the enum type names. This is moved to base visitor
- ignoreEnumValuesFromSchema: is a documents-visitor and types-visitor concern. Moved from base-visitor there.
- globalNamespace: is a documents-visitor concern. Moved from base-visitor there

Other changes:
- documents-visitor no longer extends types-visitor _option types_ as they have two distinct usages now. The types now extend base-visitor types. This is now consistent with documents-visitor extending base-visitor
- Classes now handle config parsing and types at the same level e.g. if typescript-operations plugin parses configOne, then the types for configOne must be in that class, rather than in base-documents-visitor
@changeset-bot
Copy link

changeset-bot bot commented Jan 5, 2026

🦋 Changeset detected

Latest commit: f6dd8aa

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

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

🚀 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.3-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/introspection 5.0.1-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/visitor-plugin-common 7.0.0-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 5.0.5-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/gql-tag-operations 5.0.6-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 6.0.0-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-resolvers 6.0.0-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 6.1.3-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 6.0.0-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 6.0.0-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 5.0.6-alpha-20260105125118-f6dd8aad76b522a60a52fee9cc56d3e46fc3c9a5 npm ↗︎ unpkg ↗︎

Comment on lines +404 to +414
function getRootType(operation: OperationTypeNode, schema: GraphQLSchema) {
switch (operation) {
case 'query':
return schema.getQueryType();
case 'mutation':
return schema.getMutationType();
case 'subscription':
return schema.getSubscriptionType();
}
throw new Error(`Unknown operation type: ${operation}`);
}
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 drived-by moved this function here to make the first bit of this file the related to visitor. This is done fairly consistently across the codebase now to help readability and navigation

Comment on lines -798 to -799
enumPrefix: getConfigValue(rawConfig.enumPrefix, true),
enumSuffix: getConfigValue(rawConfig.enumSuffix, true),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As mentioned in the description. This is moved to base-visitor since all 3 children visitors need it.

Comment on lines +13 to +14
enumPrefix: boolean;
enumSuffix: boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

typescript-operations (the main user of this file) now coerce null -> false, so we don't have to handle null case here.

Comment on lines -505 to -507
//
// Also use fragment hashing if skipTypename is true, since we
// then don't have a typename for naming the fragment.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is no longer relevant as we no longer have skipTypename for client use cases.

* ```
*/
noExport?: boolean;
globalNamespace?: boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is already set in base-documents-visitor so we don't have to re-declare it here.

Comment on lines -143 to -146
const processor = new PreResolveTypesProcessor(processorConfig);

this.setSelectionSetHandler(
new SelectionSetToObject(
processor,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Inlining the processor here, since we no longer have the complicated ternary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most test changes are related to skipTypename being a config option that no longer works for client use cases.

Note that since we inlined the config option in the last PR, we start to see TypeScript complaining about unexpected config options. This makes cleanups like this a lot easier.

throw new Error(`Unknown operation type: ${operation}`);
}

export interface ParsedDocumentsConfig extends ParsedTypesConfig {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, documents-visitor extends types-visitor config types, however, BaseDocumentsVisitor extends BaseVisitor, instead of BaseTypesVisitor.

This may have created some confusion (at least for me) of which option is used for which use case. This change correctly reflects the inheritance path for the visitors.

@eddeee888 eddeee888 merged commit 2e9b709 into master-next Jan 6, 2026
19 checks passed
@eddeee888 eddeee888 deleted the master-next-no-skip-typename branch January 6, 2026 11:34
eddeee888 added a commit that referenced this pull request Jan 6, 2026
* Refactor utility function to match practice

* Fix config option inheritance

- addTypename/skipTypename: is only a types-visitor concern. This is moved to types-visitor from base-visitor
- nonOptionalTypename: is a documents-visitor and types-visitor concern. Moved from base-visitor there
- extractAllFieldsToTypes: is a documents-visitor concern. Moved from base-visitor there
- enumPrefix and enumSuffix: need to be in base-visitor as all 3 types of visitors need this to correctly sync the enum type names. This is moved to base visitor
- ignoreEnumValuesFromSchema: is a documents-visitor and types-visitor concern. Moved from base-visitor there.
- globalNamespace: is a documents-visitor concern. Moved from base-visitor there

Other changes:
- documents-visitor no longer extends types-visitor _option types_ as they have two distinct usages now. The types now extend base-visitor types. This is now consistent with documents-visitor extending base-visitor
- Classes now handle config parsing and types at the same level e.g. if typescript-operations plugin parses configOne, then the types for configOne must be in that class, rather than in base-documents-visitor

* Remove references and tests related to skipTypename in operations plugin

* Add changeset
eddeee888 added a commit that referenced this pull request Jan 6, 2026
* Refactor utility function to match practice

* Fix config option inheritance

- addTypename/skipTypename: is only a types-visitor concern. This is moved to types-visitor from base-visitor
- nonOptionalTypename: is a documents-visitor and types-visitor concern. Moved from base-visitor there
- extractAllFieldsToTypes: is a documents-visitor concern. Moved from base-visitor there
- enumPrefix and enumSuffix: need to be in base-visitor as all 3 types of visitors need this to correctly sync the enum type names. This is moved to base visitor
- ignoreEnumValuesFromSchema: is a documents-visitor and types-visitor concern. Moved from base-visitor there.
- globalNamespace: is a documents-visitor concern. Moved from base-visitor there

Other changes:
- documents-visitor no longer extends types-visitor _option types_ as they have two distinct usages now. The types now extend base-visitor types. This is now consistent with documents-visitor extending base-visitor
- Classes now handle config parsing and types at the same level e.g. if typescript-operations plugin parses configOne, then the types for configOne must be in that class, rather than in base-documents-visitor

* Remove references and tests related to skipTypename in operations plugin

* Add changeset
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.

2 participants