dotansimha / dotansimha/graphql-code-generator

Mapped types are dropped when combined with unions at non-trivial depth.

Open
#5,998 6 comments 0 reactions 0 assignees View on GitHub
core help wanted stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Issue workflow progress

_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [x] 1. The issue provides a reproduction available on [Github](https://github.com/dotansimha/graphql-code-generator-issue-sandbox-template), [Stackblitz](https://stackblitz.com/github/dotansimha/graphql-code-generator-issue-sandbox-template) or [CodeSandbox](https://codesandbox.io/s/github/dotansimha/graphql-code-generator-issue-sandbox-template)

_Make sure to fork this template and run `yarn generate` in the terminal._

_Please make sure the Codegen and plugins version under `package.json` matches yours._

- [ ] 2. A failing test has been provided

- [ ] 3. A local solution has been provided

- [ ] 4. A pull request is pending review

---
**Describe the bug**
The resolver type for a type that contains a type that contains a union of types that are mapped, drops knowledge of the mapped type.

That a mouthful, but here is a minimal reproduction:

**To Reproduce**
LIve Code Sandbox: https://codesandbox.io/s/inspiring-shape-ts0t5

1. My GraphQL schema:
```graphql
type Query {
feed: FeedConnection!
}

type FeedConnection {
edge:FeedEdge
}

type FeedEdge {
node: FeedNode
}

union FeedNode = PostFeedNode | PhotoFeedNode

type PostFeedNode {
text:String
}

type PhotoFeedNode {
url:String
}
```

2. My GraphQL operations:
N/A

3. My `codegen.yml` config file:
```yml
schema: schema.graphql
generates:
types.ts:
plugins:
- typescript
- typescript-resolvers
config:
mappers:
PostFeedNode: ./model#PostFeedNodeModel
PhotoFeedNode: ./model#PhotoFeedNodeModel
```

**Expected behavior**
The resolver type should be:
`FeedConnection:ResolverTypeWrapper & { node?: Maybe }>;`

But the generated type is:
`FeedConnection: ResolverTypeWrapper;`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.