dotansimha / dotansimha/graphql-code-generator

Replace `Promise` with `PromiseLike` in resolver types

Open
#6,378 4 comments 1 reaction 0 assignees View on GitHub
core help wanted kind/enhancement
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**Is your feature request related to a problem? Please describe.**

When using non-native Promise library like Bluebird, the return type of resolvers will often be `PromiseLike`, but it doesn't adapt with generated resolver-types because the generated code is using native Promise type.

https://github.com/dotansimha/graphql-code-generator/blob/8e4d5826df7c01fec3fa26d200d171881ee3a04a/packages/plugins/typescript/resolvers/src/index.ts#L138

sample code:

```ts
const resolvers: Resolvers = {
Query: {
name: () => { // string field
return Promise.resolve('1') as PromiseLike
}
}
}
```

error message:

```
(...omitted)
Type 'PromiseLike' is not assignable to type 'ResolverTypeWrapper | Promise>'.
Type 'PromiseLike' is missing the following properties from type 'Promise>': catch, finally, [Symbol.toStringTag]
```

**Describe the solution you'd like**

Can `Promise` be just replaced with `PromiseLike`?

:memo: https://github.com/graphql/graphql-js/blob/0fef3c49907b63b1ea5a4ff1da7011775f465fc2/src/execution/execute.ts#L505-L506

**Describe alternatives you've considered**

We can customize it by using [`customResolverFn`](https://www.graphql-code-generator.com/docs/plugins/typescript-resolvers).

So this feature request is not mandatory, but I feel it's better if I don't have to customize and manage it in our code.

**Additional context**

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.