Mapped types are dropped when combined with unions at non-trivial depth.
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
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
- My GraphQL schema:
type Query {
feed: FeedConnection!
}
type FeedConnection {
edge:FeedEdge
}
type FeedEdge {
node: FeedNode
}
union FeedNode = PostFeedNode | PhotoFeedNode
type PostFeedNode {
text:String
}
type PhotoFeedNode {
url:String
}
-
My GraphQL operations: N/A
-
My
codegen.ymlconfig file:
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<Omit<FeedConnection, 'edge'> & { node?: Maybe<ResolversTypes['FeedEdge']> }>;
But the generated type is:
FeedConnection: ResolverTypeWrapper<FeedConnection>;
Hi @jacob-indieocean and thank you for the report!
Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.
It seems already got into stage 1 thanks to your reproduction! Thank you for that!
Now in order to advance to stage 2 we'll need a failing test, would be great if someone could help progress the issues through the stages.
Thank you and sorry that this comment is not a complete solution (yet).
Just thought I would add a little bit of context that I probably should have mentioned right from the start, for the sake of SEO and for the benefit of users struggling with a similar use case.
I alluded to it in the names for the types in the schema, but to be more explicit, I'm running in to this issue while conforming to the Relay spec for connections, where the node type is a union. This is probably a fairly common use case and I am surprised it has not come up already.
Actually, maybe you have seen it before. Is this a regression of #3979?
Is this a regression of #3979?
Checking should be as easy as upgrading my repro to the latest version of the codegen.
Also bumped into this today!
Bumping this again as we just ran into it.
is anyone up to move this into stage 2 by creating a failing test?
This no longer reproduces on current master (b71b9d5). With mappers for PostFeedNode and PhotoFeedNode, FeedEdge.node resolves to PostModel | PhotoModel in ResolversTypes. Probably safe to close.