Skip to content

Conversation

@ikusakov2
Copy link

@ikusakov2 ikusakov2 commented Dec 2, 2025

Description

Generates input types into target files.
Generates output enums into target files.

Related # #10496

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

  • Unit testing

@changeset-bot
Copy link

changeset-bot bot commented Dec 2, 2025

⚠️ No Changeset found

Latest commit: 7094891

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@ikusakov2 ikusakov2 changed the base branch from master to master-next December 2, 2025 01:47
);
this._declarationBlockConfig = {
ignoreExport: this.config.noExport,
enumNameValueSeparator: ' =',
Copy link
Author

Choose a reason for hiding this comment

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

I experimented with different enumType, this value appears to be required for other enumTypes to work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ikusakov2 ikusakov2 changed the title Generate Input types, Output enums into target file Generate input types and output enums into target file Dec 2, 2025
const operationsResult = oldVisit(allAst, { leave: visitor });

let operationsContent = operationsResult.definitions.join('\n');
const operationsDefinitions = operationsResult.definitions;
Copy link
Author

Choose a reason for hiding this comment

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

I rearranged/simplified the code here - please check.

operationsContent = operationsResult.definitions.concat(exportConsts).join('\n');
}

if (config.globalNamespace) {
Copy link
Author

@ikusakov2 ikusakov2 Dec 2, 2025

Choose a reason for hiding this comment

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

I moved this block to the end - to include all the generated code.

`);
});

it('try different ways to generate enums', async () => {
Copy link
Collaborator

@eddeee888 eddeee888 Dec 3, 2025

Choose a reason for hiding this comment

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

Oops sorry! I should have mentioned I'm working on the tests here: #10525

Since similar tests have been moved to standalone.enum.spec.ts, shall we remove the duplicates in this PR?

@eddeee888
Copy link
Collaborator

Sorry! I caused some conflicts in this PR after merging #10525 🙏

Comment on lines +231 to +256
private getInputObjectDeclarationBlock(node: InputObjectTypeDefinitionNode): DeclarationBlock {
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('type')
.withName(this.convertName(node))
.withComment(node.description?.value)
.withBlock((node.fields || []).join('\n'));
}

private getInputObjectOneOfDeclarationBlock(node: InputObjectTypeDefinitionNode): DeclarationBlock {
const declarationKind = (node.fields?.length || 0) === 1 ? 'type' : 'type';
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind(declarationKind)
.withName(this.convertName(node))
.withComment(node.description?.value)
.withContent(`\n` + (node.fields || []).join('\n |'));
}

private isValidVisit(ancestors: any): boolean {
const currentVisitContext = this.getVisitorKindContextFromAncestors(ancestors);
const isVisitingInputType = currentVisitContext.includes(Kind.INPUT_OBJECT_TYPE_DEFINITION);
const isVisitingEnumType = currentVisitContext.includes(Kind.ENUM_TYPE_DEFINITION);

return isVisitingInputType || isVisitingEnumType;
}
Copy link
Collaborator

@eddeee888 eddeee888 Dec 3, 2025

Choose a reason for hiding this comment

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

With utility functions that can be shared between typescript-operations and base-types-visitor like these, I wonder if we should abstract them into visitor-plugin-common now or in a following PR? 🤔

Having them in visitor-plugin-common helps ensure they'd behave the same all the time. I've done the same for Enum utilities here : https://github.com/dotansimha/graphql-code-generator/pull/10525/files#r2585220345

Comment on lines +347 to +350
const typeInfo = new TypeInfo(schema);
visit(
documentNode,
visitWithTypeInfo(typeInfo, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, this is my first time learning about this. Could you help me with the TLDR; of TypeInfo and how it helps us here?

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