dotansimha / dotansimha/graphql-code-generator

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

Open
#4,486 2 comments 2 reactions 0 assignees View on GitHub
help wanted presets stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**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:

```graphql
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!]
}

```

2. My GraphQL operations:

```graphql
query getAllUsers {
getAllUsers {
id
name
email
posts {
title
content
author {
name
}
}
}
}

```

3. My `codegen.yml` config file:

```yml
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](https://user-images.githubusercontent.com/8534915/89193628-e1b07b80-d5c3-11ea-8f96-0dbdd4bac428.png)

![image](https://user-images.githubusercontent.com/8534915/89193992-67ccc200-d5c4-11ea-93b4-6e7bc5d0e1ba.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.