Graphql-code-generator: [Bug] Typescript errors in generated file

Created on 9 Dec 2020  路  2Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
I'm getting errors on the generated file. Comparing mine to other ones, it sure looks very strange. I could go on and fix the problem manually in the file, but it'd be lost after re-generating.

Error message

Type '"[object Object]"' does not satisfy the constraint '"__typename" | "id" | "name" | "size" | "filename" | "caminho" | "type" | "idObj" | "usuarios_id"'.  TS2344

    1004 |   & { anexos?: Maybe<Array<Maybe<(
    1005 |     { __typename?: 'anexos' }
  > 1006 |     & Pick<Anexos, '[object Object]' | '[object Object]' | '[object Object]' | '[object Object]'>
         |                    ^
    1007 |   )>>> }
    1008 | );
    1009 |
  1. My GraphQL schema:
directive @cacheControl(
  maxAge: Int
  scope: CacheControlScope
) on FIELD_DEFINITION | OBJECT | INTERFACE
type anexos {
  id: ID!
  name: String!
  size: Float!
  filename: String!
  caminho: String!
  type: String!
  idObj: ID
  usuarios_id: sistema_usuarios!
}
...
type Query {
  anexos(idObj: ID): [anexos]
  anexo(id: ID!): anexos
  ...
}
...
  1. My GraphQL operations:
query Anexos($idObj: ID) {
  anexos(idObj: $idObj) {
    id
    name
    size
    type
  }
}
  1. Generated file
export type Anexos = {
  __typename?: 'anexos';
  id: Scalars['ID'];
  name: Scalars['String'];
  size: Scalars['Float'];
  filename: Scalars['String'];
  caminho: Scalars['String'];
  type: Scalars['String'];
  idObj?: Maybe<Scalars['ID']>;
  usuarios_id: Sistema_Usuarios;
};
...
export type AnexosQuery = (
  { __typename?: 'Query' }
  & { anexos?: Maybe<Array<Maybe<(
    { __typename?: 'anexos' }
    & Pick<Anexos, '[object Object]' | '[object Object]' | '[object Object]' | '[object Object]'>
  )>>> }
);
  1. My codegen.yml config file:
overwrite: true
schema: "http://localhost:3938/graphql"
documents: "src/services/gql/api/*.gql"
generates:
  src/services/gql/generated/index.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"
    config:
      whithHOC: false
      withComponents: false
      withHooks: true

Environment:

  • OS: macOS Sierra 10.12.6
  • @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
  • typescript: 4.1.2
  • NodeJS: 15.2.0

Additional context
Query works fine on Playground. The error happens in other queries too, but I can't show them here. The error started after adding this query, it was working fine before, but removing the query doesn't fix the problem.

Most helpful comment

Thanks for the quick reply. Updating solved the problem.

All 2 comments

Was this page helpful?
0 / 5 - 0 ratings