Graphql-code-generator: Invalid opertation fragment union types as of 1.6.0

Created on 20 Aug 2019  路  4Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
In 1.5.0, a query that includes a fragment generates a fragment type based on the selections of the fragment.

In 1.6.0, that same query generates only { "__typename": MyType }, regardless of what is in the selection.

To Reproduce
Generate from schema with schema

fragment PriceFragment on Price {
  id
  item {
    ... on Product {
      ...ProductFragment
  }
}

...where ProductFragment is included and contains product selections (e.g. id and name).

  1. My GraphQL schema:
    Unable to full schema.

  2. My GraphQL operations:
    This is not tied to a specfic operation, but the fragment types used in them.

  3. My codegen.yml config file:

overwrite: true
schema: schema.graphql
documents:
  [
    src/graphql/queries/**/*.graphql,
    src/graphql/fragments/**/*.graphql,
    src/graphql/mutations/**/*.graphql,
    src/graphql/subscriptions/**/*.graphql,
  ]
generates:
  src/components/graphql.tsx:
    # hooks:
    #   afterOneFileWrite:
    #     - prettier --write
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
      - fragment-matcher
    config:
      namingConvention: keep
      withHOC: false
      withHooks: true
      withComponent: true
      typesPrefix: I
      nonOptionalTypename: true
      avoidOptionals: false
      preResolveTypes: false
      dedupeOperationSuffix: true
      scalars:
        Money: number
        MoneyInput: number | string
        Decimal: number
        DecimalInput: number | string
        DateTime: string
        Date: string
  ./graphql.schema.json:
    plugins:
      - introspection

Expected behavior

export type IPriceFragment = { __typename: "Price" } & Pick<IPrice, "id"> & { item: ({ __typename: "Product" } & IProductFragment) }

Environment:

  • OS:
  • @graphql-codegen/1.6.1:
  • NodeJS: 10.14.0

** Additional Notes
The schema is generated without "errors", but the generated output is not as expected. Reverting to 1.5.0 from 1.6.0 or 1.6.1 restores the expected state of the fragments.

bug plugins waiting-for-release

Most helpful comment

Should be fixed by https://github.com/dotansimha/graphql-code-generator/pull/2409

Sorry for the inconveniences!

All 4 comments

@n1ru4l is it related to your recent changes?

Might be, @jefflewis: Can you please provide a minimal reproduction? Either a CodeSandbox or a Git Repository is fine. Is hard to guess what's wrong without having the schema.

Edit:

See https://github.com/dotansimha/graphql-code-generator/pull/2409 for reproduction.

Should be fixed by https://github.com/dotansimha/graphql-code-generator/pull/2409

Sorry for the inconveniences!

Fixed in 1.7.0

Was this page helpful?
0 / 5 - 0 ratings