Skip to content

Commit 0ffda8e

Browse files
committed
fix(codegen): resolve transitive enum types referenced by input fields
Previously, generateCustomInputTypes only followed nested types whose names ended with 'Input'. This meant enum types like VectorMetric (referenced by VectorNearbyInput.metric) were silently dropped from generated output, producing TypeScript with undefined type references. Now follows all non-scalar types that exist in the typeRegistry, including enums and other type kinds. Added unit test verifying transitive enum resolution through VectorNearbyInput → VectorMetric.
1 parent 3c4a91a commit 0ffda8e

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

graphql/codegen/src/__tests__/codegen/input-types-generator.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,63 @@ describe('plugin-injected condition fields', () => {
966966

967967
// The referenced VectorNearbyInput type should be generated as a custom input type
968968
expect(result.content).toContain('export interface VectorNearbyInput {');
969+
970+
// Transitively referenced enum type (VectorMetric) should also be generated
971+
expect(result.content).toContain('VectorMetric');
972+
expect(result.content).toContain('"L2"');
973+
expect(result.content).toContain('"INNER_PRODUCT"');
974+
expect(result.content).toContain('"COSINE"');
975+
});
976+
977+
it('generates transitively referenced enum types from input fields', () => {
978+
// This specifically tests that enum types referenced by input object fields
979+
// are followed and generated, not just types ending with "Input".
980+
// VectorNearbyInput.metric references VectorMetric (an ENUM),
981+
// which must be included in the output.
982+
const registry = createTypeRegistry({
983+
ContactCondition: {
984+
kind: 'INPUT_OBJECT',
985+
name: 'ContactCondition',
986+
inputFields: [
987+
{ name: 'id', type: createTypeRef('SCALAR', 'UUID') },
988+
{ name: 'name', type: createTypeRef('SCALAR', 'String') },
989+
{
990+
name: 'embeddingNearby',
991+
type: createTypeRef('INPUT_OBJECT', 'VectorNearbyInput'),
992+
},
993+
],
994+
},
995+
VectorNearbyInput: {
996+
kind: 'INPUT_OBJECT',
997+
name: 'VectorNearbyInput',
998+
inputFields: [
999+
{
1000+
name: 'vector',
1001+
type: createNonNull(createTypeRef('SCALAR', 'Vector')),
1002+
},
1003+
{
1004+
name: 'metric',
1005+
type: createTypeRef('ENUM', 'VectorMetric'),
1006+
},
1007+
],
1008+
},
1009+
VectorMetric: {
1010+
kind: 'ENUM',
1011+
name: 'VectorMetric',
1012+
enumValues: ['L2', 'INNER_PRODUCT', 'COSINE'],
1013+
},
1014+
});
1015+
1016+
const result = generateInputTypesFile(registry, new Set(), [contactTable]);
1017+
1018+
// VectorNearbyInput should be generated (follows *Input pattern)
1019+
expect(result.content).toContain('export interface VectorNearbyInput {');
1020+
1021+
// VectorMetric enum should ALSO be generated (transitive enum resolution)
1022+
expect(result.content).toMatch(/export type VectorMetric\s*=/);
1023+
expect(result.content).toContain('"L2"');
1024+
expect(result.content).toContain('"INNER_PRODUCT"');
1025+
expect(result.content).toContain('"COSINE"');
9691026
});
9701027

9711028
it('does not duplicate fields already derived from table columns', () => {

graphql/codegen/src/core/codegen/orm/input-types-generator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,12 +1616,13 @@ function generateCustomInputTypes(
16161616
description: stripSmartComments(field.description, comments),
16171617
});
16181618

1619-
// Follow nested Input types
1619+
// Follow nested types (Input objects, Enums, etc.) that exist in the registry
16201620
const baseType = getTypeBaseName(field.type);
16211621
if (
16221622
baseType &&
1623-
baseType.endsWith('Input') &&
1624-
!generatedTypes.has(baseType)
1623+
!SCALAR_NAMES.has(baseType) &&
1624+
!generatedTypes.has(baseType) &&
1625+
typeRegistry.has(baseType)
16251626
) {
16261627
typesToGenerate.add(baseType);
16271628
}

0 commit comments

Comments
 (0)