dotansimha / dotansimha/graphql-code-generator
typescript-operations: Missing types with a nested fragment when exportFragmentSpreadSubTypes and skipTypename are enabled
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
When both `exportFragmentSpreadSubTypes` and `skipTypename` are `true`, some types are not generated when a fragment has certain nested objects.
**To Reproduce**
Reproduction here: https://codesandbox.io/s/great-noyce-wdyut
Missing types are shown in the `no-undef` lint errrors.
1. My GraphQL schema:
```graphql
interface BlockInterface {
uid: String
title: String
}
type Root_BlockType implements BlockInterface {
uid: String
title: String
children: [BlockInterface]
}
type Child_BlockType implements BlockInterface {
uid: String
title: String
children: [BlockInterface]
}
type FragmentOne_Type implements BlockInterface {
uid: String
title: String
}
type FragmentTwo_Type implements BlockInterface {
uid: String
title: String
}
type FragmentThree_Type implements BlockInterface {
uid: String
title: String
}
union Blocks = Root_BlockType | Child_BlockType
type Result implements BlockInterface {
uid: String
title: String
blocks: Blocks
}
type Query {
search: BlockInterface
}
```
2. My GraphQL operations:
```graphql
fragment RootBlockFields on Root_BlockType {
__typename
uid
}
fragment RootChildren on BlockInterface {
...FragmentOne
...FragmentTwo
}
fragment RootBlock on Root_BlockType {
...RootBlockFields
children {
...RootChildren
...ChildBlock
}
}
fragment ChildChildren on BlockInterface {
...FragmentOne
...FragmentTwo
...FragmentThree
}
fragment ChildBlock on Child_BlockType {
__typename
uid
children {
...ChildChildren
...on Root_BlockType {
...RootChildren
children {
...on Child_BlockType {
__typename
uid
children {
...ChildChildren
}
}
}
}
}
}
fragment FragmentOne on FragmentOne_Type {
__typename
uid
}
fragment FragmentTwo on FragmentTwo_Type {
__typename
uid
title
}
fragment FragmentThree on FragmentThree_Type {
__typename
uid
title
}
query SampleQuery {
search {
...on Result {
__typename
blocks {
...RootBlock
}
}
}
}
```
3. My `codegen.yml` config file:
```yml
schema: schema.graphql
documents: document.graphql
generates:
types.ts:
plugins:
- typescript
- typescript-operations
config:
exportFragmentSpreadSubTypes: true
skipTypename: true
```
**Expected behavior**
All types should be generated. Instead, the generated operation types reference the following types that are not defined:
- `RootChildren_Root_BlockType_Fragment`
- `RootChildren_Child_BlockType_Fragment`
- `RootChildren_FragmentThree_Type_Fragment`
- `RootChildren_Result_Fragment`
- `ChildChildren_Root_BlockType_Fragment`
- `ChildChildren_Child_BlockType_Fragment`
- `ChildChildren_Result_Fragment`
**Environment:**
- OS: MacOS
- `@graphql-codegen/...`: 1.17.10
- `@graphql-codegen/typescript-operations`: 1.17.8
- NodeJS: 12.15
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.