@@ -1556,6 +1556,113 @@ describe('extractAllFieldsToTypes: true', () => {
15561556 await validate ( content , config , nestedInterfacesSchema ) ;
15571557 } ) ;
15581558
1559+ it ( 'fragment spreads on the same interface should not force concrete parent type names (regression #10502)' , async ( ) => {
1560+ const interfaceFragmentSchema = buildSchema ( /* GraphQL */ `
1561+ schema {
1562+ query: Query
1563+ }
1564+
1565+ type Query {
1566+ pet(petId: ID!): Pet
1567+ }
1568+
1569+ interface Pet {
1570+ id: ID!
1571+ home: Home
1572+ }
1573+
1574+ type Dog implements Pet {
1575+ id: ID!
1576+ home: Home
1577+ }
1578+
1579+ type Cat implements Pet {
1580+ id: ID!
1581+ home: Home
1582+ }
1583+
1584+ interface Home {
1585+ id: ID!
1586+ }
1587+
1588+ type House implements Home {
1589+ id: ID!
1590+ }
1591+ ` ) ;
1592+
1593+ const interfaceFragmentDoc = parse ( /* GraphQL */ `
1594+ fragment GetFragmentPet on Pet {
1595+ id
1596+ home {
1597+ id
1598+ }
1599+ }
1600+
1601+ query GetPetData($petId: ID!) {
1602+ pet(petId: $petId) {
1603+ id
1604+ home {
1605+ id
1606+ }
1607+ ...GetFragmentPet
1608+ }
1609+ }
1610+ ` ) ;
1611+
1612+ const config : TypeScriptDocumentsPluginConfig = {
1613+ preResolveTypes : true ,
1614+ extractAllFieldsToTypes : true ,
1615+ nonOptionalTypename : true ,
1616+ dedupeOperationSuffix : true ,
1617+ } ;
1618+
1619+ const { content } = await plugin (
1620+ interfaceFragmentSchema ,
1621+ [ { location : 'test-file.ts' , document : interfaceFragmentDoc } ] ,
1622+ config ,
1623+ { outputFile : '' }
1624+ ) ;
1625+
1626+ // Edge case: a fragment spread on the same interface should not cause extracted types
1627+ // for interface fields to be rooted to the first concrete parent (e.g. Cat).
1628+ expect ( content ) . toMatchInlineSnapshot ( `
1629+ "export type GetFragmentPetFragment_Pet_home_House = { __typename: 'House', id: string };
1630+
1631+ type GetFragmentPet_Dog_Fragment = { __typename: 'Dog', id: string, home?: GetFragmentPetFragment_Pet_home_House | null };
1632+
1633+ type GetFragmentPet_Cat_Fragment = { __typename: 'Cat', id: string, home?: GetFragmentPetFragment_Pet_home_House | null };
1634+
1635+ export type GetFragmentPetFragment =
1636+ | GetFragmentPet_Dog_Fragment
1637+ | GetFragmentPet_Cat_Fragment
1638+ ;
1639+
1640+ export type GetPetDataQuery_pet_Pet_home_House = { __typename: 'House', id: string };
1641+
1642+ export type GetPetDataQuery_pet_Dog = { __typename: 'Dog', id: string, home?: GetPetDataQuery_pet_Pet_home_House | null };
1643+
1644+ export type GetPetDataQuery_pet_Cat = { __typename: 'Cat', id: string, home?: GetPetDataQuery_pet_Pet_home_House | null };
1645+
1646+ export type GetPetDataQuery_pet =
1647+ | GetPetDataQuery_pet_Dog
1648+ | GetPetDataQuery_pet_Cat
1649+ ;
1650+
1651+ export type GetPetDataQuery_Query = { __typename: 'Query', pet?: GetPetDataQuery_pet | null };
1652+
1653+
1654+ export type GetPetDataQueryVariables = Exact<{
1655+ petId: Scalars['ID']['input'];
1656+ }>;
1657+
1658+
1659+ export type GetPetDataQuery = GetPetDataQuery_Query;
1660+ "
1661+ ` ) ;
1662+
1663+ await validate ( content , config , interfaceFragmentSchema ) ;
1664+ } ) ;
1665+
15591666 // Exception case for Issue #10502 - shared schema for fragment tests
15601667 const notificationSchema = buildSchema ( /* GraphQL */ `
15611668 type Query {
0 commit comments