Skip to content

Conversation

@Georgegriff
Copy link
Contributor

@Georgegriff Georgegriff commented Jan 21, 2026

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

Description

This is another edge case follow on that i've found from this original issue turns out in a 7+ year old graphql codebase there are many demons and dragons lurking in the code with weird patterns that work... even if they shouldn't
#10502

I've captured the following schema into a testcase which shows the issue, but here is a description:

With extractAllFieldsToTypes: true, extracted field types for interface fields use the first concrete type name instead of the interface name. This only happens when using fragment spreads in the query.

Expected: GetPetData_pet_Pet_home
Actual: GetPetData_pet_Cat_home (and reused across all concrete types)

Files

schema.graphql:

type Query {
  pet(petId: ID!): Pet
}

interface Pet {
  id: ID!
  home: Home
}

type Dog implements Pet {
  id: ID!
  home: Home
}

type Cat implements Pet {
  id: ID!
  home: Home
}

interface Home {
  id: ID!
  title: String
}

type House implements Home {
  id: ID!
  title: String
}

queries.ts:

import { gql } from "@apollo/client/core";

const GetHeaderDataFragment = gql`
  fragment GetHeaderData on Pet {
    id
    home {
      id
      title
    }
  }
`;

export const PET_DATA_QUERY = gql`
  query GetPetData($petId: ID!) {
    pet(petId: $petId) {
      id
      home {
        id
      }
      ...GetHeaderData
    }
  }
  ${GetHeaderDataFragment}
`;

Generated Output

// Wrong: uses concrete type "Cat" instead of interface "Pet"
export type GetPetData_pet_Cat_home_House = { __typename: 'House', id: string, title: string | null };

export type GetPetData_pet_Cat = { 
  __typename: 'Cat', 
  id: string, 
  home: GetPetData_pet_Cat_home_House | null 
};

export type GetPetData_pet_Dog = { 
  __typename: 'Dog', 
  id: string, 
  home: GetPetData_pet_Cat_home_House | null  // Should be GetPetData_pet_Pet_home_House
};

Expected Output

export type GetPetData_pet_Pet_home_House = { __typename: 'House', id: string, title: string | null };

export type GetPetData_pet_Cat = { 
  __typename: 'Cat', 
  id: string, 
  home: GetPetData_pet_Pet_home_House | null 
};

export type GetPetData_pet_Dog = { 
  __typename: 'Dog', 
  id: string, 
  home: GetPetData_pet_Pet_home_House | null 
};

Related # (issue)

#10502

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

New test case added and no other existing tests in the extract type suite were impacted

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@changeset-bot
Copy link

changeset-bot bot commented Jan 21, 2026

🦋 Changeset detected

Latest commit: f1529b8

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

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

@eddeee888
Copy link
Collaborator

Thank you @Georgegriff !
@ikusakov2 has been working on a similar area for the next major version release: #10496

I wonder if this is a missed edge case or it's taken care in the new version @ikusakov2

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