dotansimha / dotansimha/graphql-code-generator

Allow typescript-resolvers plugin to export resolver function alias type

Open
#7,373 0 comments 0 reactions 0 assignees View on GitHub
core kind/enhancement plugins
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.**

Currently root resolver types exported the following way:

```TS
export type QueryResolvers = {
accounts?: Resolver>>, ParentType, ContextType>;
};
```

the `accounts` type `Resolver>>, ParentType, ContextType>;` is too long and complex to reuse it in TS files, for example, when I need to define resolver functions in the separate file and define its type:

```TS
export const accountsResolver: Resolver>>, ParentType, ContextType> = async (_, __, ctx) => {
const res = ...

return res.map(item => {
return {
id: item._id.toString(),
name: item.name,
balance: item.balance || 0,
};
});
};
```

**Describe the solution you'd like**

I propose to add additional optional config parameter, and in addition to this long construction generate alias for it:

```TS
export type AccountsResolverFn = Resolver>>, ParentType, ContextType> | undefined;

```

with this change the code becomes much simpler:

```TS
export const accountsResolver: AccountsResolverFn = async (_, __, ctx) => {
const res = ...

return res.map(item => {
return {
id: item._id.toString(),
name: item.name,
balance: item.balance || 0,
};
});
};
```

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.