Graphql-code-generator: Typescript Client with noNamespaces: field value doesn't match generated name of inlineFragments

Created on 3 Dec 2018  路  2Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
When graphql-codegen-typescript-client is configured with noNamespaces: true and a field value is a union of graphQL types, the field's value references the wrong name for the generated inlineFragments type. It appears the prefix is missing.

To Reproduce
Using this mouthwatering example in the demo app:

schema:

schema {
  query: Query
}

type Query {
  me: User
  user(id: ID!): User
}

type Pizza {
  dough: String!
  toppings: [String!]
}

type Hamburger {
  patty: String!
  toppings: [String!]
}

union FavoriteFood = Pizza | Hamburger

type User {
  id: ID!
  favoriteFood: FavoriteFood!
}

document:

query findUser($userId: ID!) {
  user(id: $userId) {
    id
  favoriteFood {
    ...on Pizza {
      dough
      toppings
    }
    ... on Hamburger {
      patty
      toppings
    }
  }
  }
}

config:

config:
    noNamespaces: true
generates:
  client-types.ts:
    - typescript-common
    - typescript-client

generated:

export type FindUserVariables = {
    userId: string
}

export type FindUserQuery = {
    __typename?: 'Query'
    user: FindUserUser | null
}

export type FindUserUser = {
    __typename?: 'User'
    id: string
    favoriteFood: FavoriteFood
}

export type FindUserFavoriteFood = FindUserPizzaInlineFragment | FindUserHamburgerInlineFragment

export type FindUserPizzaInlineFragment = {
    __typename?: 'Pizza'
    dough: string
    toppings: string[] | null
}

export type FindUserHamburgerInlineFragment = {
    __typename?: 'Hamburger'
    patty: string
    toppings: string[] | null
}

Expected behavior

generated:

...
export type FindUserUser = {
    __typename?: 'User'
    id: string
    favoriteFood: FindUserFavoriteFood // <= MUST MATCH TYPE NAME BELOW
}

export type FindUserFavoriteFood = FindUserPizzaInlineFragment | FindUserHamburgerInlineFragment
...

Schema/Documents
If possible and relevant, please provide your GraphQL schema and GraphQL documents.

Environment:

  • OS: MacOs 10.12.6
  • Codegen: 14.5
  • Node: 10.13.0

Additional context
Add any other context about the problem here.

bug plugins waiting-for-release

Most helpful comment

Fixed in #983

All 2 comments

Fixed in #983

Released in v0.15.0

Was this page helpful?
0 / 5 - 0 ratings