graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Type suffix placed incorrectly in query variables type

Open jaitd opened this issue 6 years ago • 3 comments

Describe the bug

Operation and variables types are incorrectly named when generated with the typesSuffix config option.

To Reproduce

The repro is available here: https://codesandbox.io/s/focused-allen-42r9f?file=/types.ts:655-681.

  1. My GraphQL schema:
type Query {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String!
}
  1. My GraphQL operations:
query user {
    user(id: 1) {
        id
        username
        email
    }
}
  1. My codegen.yml config file:
schema: schema.graphql
documents: document.graphql
generates:
  types.ts:
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      withHooks: false
      typesSuffix: 'Type'

Expected behavior

The generated type name should be UserQueryType and UserQueryVariablesType but instead it is UserTypeQueryType and UserTypeQueryVariablesType

Environment:

  • @graphql-codegen/add: 2.0.1
  • @graphql-codegen/cli: 1.19.0
  • @graphql-codegen/typescript: 1.17.11
  • @graphql-codegen/typescript-operations: 1.17.8
  • @graphql-codegen/typescript-react-apollo: 2.0.7
  • graphql: 15.3.0
  • NodeJS: 10.x

Additional context

There was another bug report in the similar vein which was already resolved: #4687

jaitd avatar Oct 29 '20 11:10 jaitd

Hi @jaitd , I managed to fix this issue in: https://github.com/dotansimha/graphql-code-generator/pull/5038

Can you please give the alpha version a try? it's @graphql-codegen/[email protected]

dotansimha avatar Nov 04 '20 17:11 dotansimha

Fixed in @graphql-codegen/[email protected].

dotansimha avatar Nov 05 '20 08:11 dotansimha

Thanks @dotansimha. It works now 😄

jaitd avatar Nov 05 '20 10:11 jaitd