dotansimha/graphql-code-generator

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

Open

#5998 aperta il 14 mag 2021

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)TypeScript (1295 fork)batch import
corehelp wantedstage/1-reproduction

Metriche repository

Star
 (10.341 star)
Metriche merge PR
 (Merge medio 22g 9h) (53 PR mergiate in 30 g)

Descrizione

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>;

Guida contributor