Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 4 tasks
Tracked by #8296 ...
jacob-indieocean opened this issue May 14, 2021 · 6 comments
Open
1 of 4 tasks
Tracked by #8296 ...
Labels
core Related to codegen core/cli help wanted Extra attention is needed stage/1-reproduction A reproduction exists

Comments

@jacob-indieocean
Copy link

jacob-indieocean commented May 14, 2021

Issue workflow progress

Progress of the issue based on the Contributor Workflow

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:
type Query {
    feed: FeedConnection!
}

type FeedConnection {
    edge:FeedEdge
}

type FeedEdge {
    node: FeedNode
}

union FeedNode = PostFeedNode | PhotoFeedNode

type PostFeedNode {
    text:String
}

type PhotoFeedNode {
    url:String
}
  1. My GraphQL operations:
    N/A

  2. My codegen.yml config 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>;

@Urigo Urigo added the stage/1-reproduction A reproduction exists label May 14, 2021
@Urigo
Copy link
Collaborator

Urigo commented May 14, 2021

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).

@jacob-indieocean
Copy link
Author

jacob-indieocean commented May 14, 2021

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?

@darkbasic
Copy link
Contributor

Is this a regression of #3979?

Checking should be as easy as upgrading my repro to the latest version of the codegen.

@mengyazhu96
Copy link

Also bumped into this today!

@aitskovi
Copy link

Bumping this again as we just ran into it.

@Urigo
Copy link
Collaborator

Urigo commented Apr 23, 2022

is anyone up to move this into stage 2 by creating a failing test?

@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli help wanted Extra attention is needed stage/1-reproduction A reproduction exists
Projects
None yet
Development

No branches or pull requests

7 participants