dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.83k stars 1.33k forks source link

[typescript-operations] Exported fragment type is not in Query #7416

Open Kevin-Seo opened 2 years ago

Kevin-Seo commented 2 years ago

Describe the bug Exported fragment type is not in query

To Reproduce

  1. Go to "https://www.graphql-code-generator.com/"
  2. Choose Live Example to "Operations Types"
  3. Add to codegen.yml below:
    config:
      exportFragmentSpreadSubTypes: true

    (However it's the same if you don't do this one)

  4. Check operations-types.ts
    
    export type FindUserQuery = { __typename?: 'Query', user?: { __typename?: 'User', id: string, username: string, role: Role } | null | undefined };

export type UserFieldsFragment = { __typename?: 'User', id: string, username: string, role: Role };


**Expected behavior**

// Type of FindUserQuery.user should includes UserFieldsFragment !!! export type FindUserQuery = { __typename?: 'Query', user?: UserFieldsFragment | null | undefined };

export type UserFieldsFragment = { __typename?: 'User', id: string, username: string, role: Role };



**Environment:**
You can reproduce on the official website live demo (https://www.graphql-code-generator.com/)

<img width="1450" alt="스크린샷 2022-01-27 오전 12 24 54" src="https://user-images.githubusercontent.com/22269850/151192541-dfa52fdf-8d09-4e31-b9e9-f2308f5a97cf.png">
charlypoly commented 2 years ago

Hi @Kevin-Seo,

Using the inlineFragmentTypes: "combine" option should give you the expected type definitions.

cf: https://www.graphql-code-generator.com/plugins/typescript