dotansimha/graphql-code-generator

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

Open

#4486 aperta il 3 ago 2020

Vedi su GitHub
 (2 commenti) (2 reazioni) (0 assegnatari)TypeScript (1295 fork)batch import
help wantedpresetsstage/1-reproduction

Metriche repository

Star
 (10.341 star)
Metriche merge PR
 (Merge medio 22g 9h) (53 PR mergiate in 30 g)

Descrizione

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

Guida contributor