Graphql-code-generator: Unable to request field __typename when using the near-operation-file Preset

Created on 26 Oct 2019  路  4Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

It seems the __typename field cannot be requested in a query when using the near-operation-file preset.

To Reproduce
Steps to reproduce the behavior:
The bug can be reproduced in this sandbox: https://codesandbox.io/s/graphql-codegen-issue-template-95ugn

  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) {
        __typename
        id
        username
    }
}

  1. My codegen.yml config file:
schema: schema.graphql
documents: document.graphql
generates:
  types.ts:
    preset: near-operation-file
    presetConfig:
      baseTypesPath: types.ts
    plugins:
      - typescript
      - typescript-operations

Expected behavior

I would expect the types to be generated as normal with a non-null __typename field when it is asked for.
Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

Additional context

Removing the preset allows this to work as expected.

bug presets waiting-for-release

All 4 comments

fwiw this also happens if you use fragments with __typename, which is how I came across the issue: https://codesandbox.io/s/graphql-codegen-issue-template-6vv5g

@seansfkelley I think I managed to fix this issue in: https://github.com/dotansimha/graphql-code-generator/commit/d70efb5045e31ee0b331170314e0f4204be4c911

Can you please try the alpha version? 1.8.3-alpha-691249fe.22

@dotansimha I can confirm that 1.8.3-alpha-691249fe.22 fixes the issue. Thank you very much!

Fixed in 1.8.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  路  3Comments

SimenB picture SimenB  路  3Comments

fvisticot picture fvisticot  路  3Comments

leebenson picture leebenson  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments