From 7719c3415cf2f2c8c769f17436f695089d8d781f Mon Sep 17 00:00:00 2001 From: Georgegriff Date: Fri, 14 Nov 2025 17:13:57 +0000 Subject: [PATCH 1/3] added failing test case --- .../tests/extract-all-types.spec.ts | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts b/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts index c64468cf85c..011578f3875 100644 --- a/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts +++ b/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts @@ -1462,4 +1462,97 @@ describe('extractAllFieldsToTypes: true', () => { await validate(content, config, complexTestSchemaWithUnionsAndInterfaces); }); + it('should handle nested interfaces with same fields correctly (issue #10502)', async () => { + const nestedInterfacesSchema = buildSchema(/* GraphQL */ ` + type Query { + animals: [Animal!] + } + + interface Animal { + name: String! + owner: Person! + } + + type Cat implements Animal { + name: String! + owner: Person! + } + + type Dog implements Animal { + name: String! + owner: Person! + } + + interface Person { + name: String! + } + + type Trainer implements Person { + name: String! + } + + type Veterinarian implements Person { + name: String! + } + `); + + const nestedInterfacesQuery = parse(/* GraphQL */ ` + query GetAnimals { + animals { + name + owner { + name + } + } + } + `); + + const config: TypeScriptDocumentsPluginConfig = { + preResolveTypes: true, + extractAllFieldsToTypes: true, + nonOptionalTypename: true, + dedupeOperationSuffix: true, + }; + + const { content } = await plugin( + nestedInterfacesSchema, + [{ location: 'test-file.ts', document: nestedInterfacesQuery }], + config, + { outputFile: '' } + ); + + // Issue #10502: When nested interfaces have the same fields, extractAllFieldsToTypes + // We need to use the interface name for the nested type name. + + expect(content).toMatchInlineSnapshot(` + "export type GetAnimalsQuery_animals_Animal_owner_Trainer = { __typename: 'Trainer', name: string }; + + export type GetAnimalsQuery_animals_Animal_owner_Veterinarian = { __typename: 'Veterinarian', name: string }; + + export type GetAnimalsQuery_animals_Animal_owner = + | GetAnimalsQuery_animals_Animal_owner_Trainer + | GetAnimalsQuery_animals_Animal_owner_Veterinarian + ; + + export type GetAnimalsQuery_animals_Cat = { __typename: 'Cat', name: string, owner: GetAnimalsQuery_animals_Animal_owner }; + + export type GetAnimalsQuery_animals_Dog = { __typename: 'Dog', name: string, owner: GetAnimalsQuery_animals_Animal_owner }; + + export type GetAnimalsQuery_animals = + | GetAnimalsQuery_animals_Cat + | GetAnimalsQuery_animals_Dog + ; + + export type GetAnimalsQuery_Query = { __typename: 'Query', animals?: Array | null }; + + + export type GetAnimalsQueryVariables = Exact<{ [key: string]: never; }>; + + + export type GetAnimalsQuery = GetAnimalsQuery_Query; + " + `); + + await validate(content, config, nestedInterfacesSchema); + }); }); From 0234c8bd4eec934a19f743d58073f2b04026d0c1 Mon Sep 17 00:00:00 2001 From: Georgegriff Date: Fri, 14 Nov 2025 17:47:27 +0000 Subject: [PATCH 2/3] possible fix --- .../src/selection-set-to-object.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts index db91a42a2bf..bee9f0ec7d3 100644 --- a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts +++ b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts @@ -958,7 +958,24 @@ export class SelectionSetToObject Date: Fri, 14 Nov 2025 17:52:45 +0000 Subject: [PATCH 3/3] imporve test name --- .../typescript/operations/tests/extract-all-types.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts b/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts index 011578f3875..49cbb166f0a 100644 --- a/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts +++ b/packages/plugins/typescript/operations/tests/extract-all-types.spec.ts @@ -1462,7 +1462,7 @@ describe('extractAllFieldsToTypes: true', () => { await validate(content, config, complexTestSchemaWithUnionsAndInterfaces); }); - it('should handle nested interfaces with same fields correctly (issue #10502)', async () => { + it('should handle interfaces without fragments', async () => { const nestedInterfacesSchema = buildSchema(/* GraphQL */ ` type Query { animals: [Animal!]