Graphql-code-generator: incorrect types on fragments

Created on 23 Aug 2019  路  11Comments  路  Source: dotansimha/graphql-code-generator

we're getting incorrect types on some generated types, see below. I commented on the final snippet in the generated code where the types are seemingly wrong

type DashboardTileChartDetails {
  tileId: String!
  wsId: UUID!
  chartId: String!
  md: TileChartMetadata # null if we error out
}

type TileChartMetadata {
  connection: Connection!
  viz: JsonBlob!
  columnInfo: JsonBlob! # the ColumnInfo type;
}

type DashboardTileFilterDetails {
  tileId: String!
  md: TileFilterMetadata
}
const DashboardVersionFragment = gql`
  fragment DashboardVersionFragment on DashboardVersion {
    ...DocumentVersionFragment
    tiles {
      ... on DashboardTileChartDetails {
        tileId
        wsId
        chartId
        md {
          viz
          columnInfo
          connection {
            ...ConnectionFragment
          }
        }
      }
      ... on DashboardTileFilterDetails {
        tileId
        md {
          columnType
          connection {
            ...ConnectionFragment
          }
        }
      }
      ... on DashboardTileParameterDetails {
        tileId
        md {
          parameterConstraint
          parameterLabel
        }
      }
    }
  }
  ${DocumentVersionFragment}
  ${ConnectionFragment}
`;
export type DashboardVersionFragmentFragment = (
  { __typename?: 'DashboardVersion' }
  & { tiles: Array<(
    { __typename?: 'DashboardTileChartDetails' }
    & Pick<DashboardTileChartDetails, 'tileId' | 'wsId' | 'chartId'>
    & { md: Maybe<(
      { __typename?: 'TileChartMetadata' }
      & Pick<TileChartMetadata, 'viz' | 'columnInfo'>
      & { connection: { __typename?: 'Connection' }
        & ConnectionFragmentFragment
       }
    )> }
  ) | (
    { __typename?: 'DashboardTileFilterDetails' }
    & Pick<DashboardTileFilterDetails, 'tileId'>
    & { md: Maybe<(
      { __typename?: 'TileChartMetadata' }
      & Pick<TileChartMetadata, 'columnType'> // should pick TileFilterMetadata
      & { connection: { __typename?: 'Connection' }
        & ConnectionFragmentFragment
       }
    )> }
  ) | { __typename?: 'DashboardTileTextDetails' } | (
    { __typename?: 'DashboardTileParameterDetails' }
    & Pick<DashboardTileParameterDetails, 'tileId'>
    & { md: Maybe<(
      { __typename?: 'TileChartMetadata' }
      & Pick<TileChartMetadata, 'parameterConstraint' | 'parameterLabel'> // should pick TileParameterMetadata
    )> }
  )> }
)
  & DocumentVersionFragmentFragment
;
;
bug plugins waiting-for-release

All 11 comments

Is the field tiles a union or interface? Please provide all referenced type definitions.

sure here's some more context:

type DashboardVersion implements DocumentVersionInterface {
  version: Int!
  document: JsonBlob!
  description: String

  createdBy: OrgMember!
  updatedBy: OrgMember!

  createdAt: DateTime!
  updatedAt: DateTime!

  tiles: [DashboardTile!]!
}
union DashboardTile =
    DashboardTileChartDetails
  | DashboardTileFilterDetails
  | DashboardTileTextDetails
  | DashboardTileParameterDetails

I also created a reproduction using interfaces instead of unions (see https://github.com/dotansimha/graphql-code-generator/pull/2437)

so this is confirmed to be a bug? i wanted to be sure we weren't discovering some issue with our schema through the type generation

Yes it is a bug caused by some code that I forgot to delete when fixing union/interface types 馃槄

I fixed it in https://github.com/dotansimha/graphql-code-generator/pull/2437

I added tests for both unions and interfaces to ensure there will be no regression!

I'm experiencing this issue as well, thank you to have fixed it 馃憤

Fixed in 1.7.0
thanks @n1ru4l

fwiw this is still broken in 1.8.2

@bwiklund Could you please provide a code sandbox example or a failing test?

Just as @n1ru4l said, can you please share a reproduction of this? @bwiklund ?

sorry, i dont have the bandwidth to recreate this entire environment for a repro. it's the same bug as original reported

Was this page helpful?
0 / 5 - 0 ratings