Graphql-code-generator: "preResolveTypes" Fragment not respected in GraphQL conditional fragment

Created on 24 Sep 2019  路  3Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

When having preResolveTypes enabled Fragment used within a GraphQL ... on SomeType is not generated.

GraphQL

query SomeQuery {
  object {
    id
    ... on SomeType {
      name
      ...FragmentName
    }
  }
}

TypeScript (_no fragment in the type_)

type SomeQuery {
  object: Maybe<(
    | { id: string }
    | { id: string; name: string }
  )>;
}

Without the preResolveTypes types is correctly generated
TypeScript

type SomeQuery {
  object: Maybe<(
    | Pick<GlobalType, 'id'>
    | Pick<AnotherType, 'id' | 'name'> & FragmentName
  )>;
}

_Please not I wrote all the queries and generated types by hand_

To Reproduce
Steps to reproduce the behavior:

  • Create a query with a fragment usage similar to above
  • Enable preResolveTypes
  • Generate the types
  1. My codegen.yml config file:
overwrite: true
schema: "http://localhost:4000/graphql"
documents: "./projects/**/*.graphql.ts"
generates:
  ./generated/graphql.d.ts:
    plugins:
      - "typescript"
      - "typescript-operations"
    config:
      avoidOptionals: true
      dedupeOperationSuffix: true
      immutableTypes: true
      # preResolveTypes: true
      nonOptionalTypename: true
      declarationKind: "interface"
  ./generated/schema.json:
    plugins:
      - "introspection"
  ./generated/introspection-result.ts:
    plugins:
      - fragment-matcher

Expected behavior

Environment:

bug plugins waiting-for-release

All 3 comments

@klemenoslaj Can you please try the latest alpha version? 1.7.1-alpha-1e9152fb.90, it has major fixes for the selection set transformation, and I think I fixed this issue as well.

@dotansimha, just checked it, and yes, it's indeed fixed in this alpha version.
Thanks for the great work :+1:

Fixed in 1.8.0 馃殌

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rogerg93 picture rogerg93  路  3Comments

fvisticot picture fvisticot  路  3Comments

jagregory picture jagregory  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments

edorivai picture edorivai  路  3Comments