dotansimha/graphql-code-generator

Unused base types from operations.ts file in generated hooks [typescript-urql + import-types preset]

Open

#4,486 创建于 2020年8月3日

在 GitHub 查看
 (2 评论) (2 反应) (0 负责人)TypeScript (10,341 star) (1,295 fork)batch import
help wantedpresetsstage/1-reproduction

描述

Description when using typescript-urql plugin along with import-types preset the generated hooks are not using the base types from the generated operations.ts file

  1. My GraphQL schema:
type Mutation {
  createUser(email: String!, name: String!): User!
}

type Post {
  author: User
  authorId: Int!
  content: String
  id: Int!
  published: Boolean!
  title: String!
}

type Query {
  getAllPosts: [Post!]!
  getAllUsers: [User!]!
  getUserByEmail(email: String): User!
}

type User {
  email: String!
  id: Int!
  name: String!
  posts: [Post!]
}

  1. My GraphQL operations:
query getAllUsers {
  getAllUsers {
    id
    name
    email
    posts {
      title
      content
      author {
        name
      }
    }
  }
}

  1. My codegen.yml config file:
overwrite: true
schema: 'http://localhost:3000/api'

hooks:
  afterAllFileWrite:
    - eslint --fix

generates:
  generated/schemas.ts:
    documents: 'graphql/**/*.graphql'
    plugins:
      - typescript

  generated/operations.ts:
    documents: 'graphql/**/*.graphql'
    preset: import-types
    presetConfig:
      typesPath: ./schemas
      importTypesNamespace: SchemaTypes
    plugins:
      - typescript-operations

  generated/hooks.ts:
    documents: 'graphql/**/*.graphql'
    preset: import-types
    presetConfig:
      typesPath: ./operations
      importTypesNamespace: OperationTypes
    plugins:
      - typescript-urql
    config:
      withHOC: false
      withComponent: false
      withHooks: true

Expected behavior the generated hooks.ts file must use the imported base types from the operations.ts file. the types from the schema.ts file is used in the operations.ts file but the same is not reflecting in the hooks.ts file

Environment:

  • OS: mac
  • Node: v10.13.0
  • @graphql-codegen/cli: 1.17.6
  • @graphql-codegen/typescript-urql: 1.17.6

Additional context image

image

贡献者指南