Type Generation for Plan Resolvers
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 625
- Avg merge
- 5h 23m
- Merged PRs (30d)
- 24
Description
Currently there is no TypeScript type generation tool for Plan Resolvers, similar to graphql-codegen for graphql.js.
I wrote a small utility type available to convert types generated from [@graphql-codegen/typescript-resolvers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) to work with Grafast:
```typescript
export type PlanResolversFromRawResolversType = {
[P in keyof Resolvers]: {
[Q in keyof NonNullable]: PlanResolverFromRawResolverType[Q]>
};
};
type PlanResolverFromRawResolverType = T extends (parent: infer TParent, args: infer TArgs, ...rest: any) => infer TResult
? ($parent: ExecutableStep, args: { [TKey in keyof TArgs as `$${TKey & string}`]: ExecutableStep }) => ExecutableStep>
: never;
type ExtractResult = Awaited extends readonly (infer Q | Promise)[]
? readonly Q[]
: Awaited
// Usage:
import { Resolvers } from './graphql-codegen-generated.ts';
export const planResolvers: PlanResolversFromRawResolversType = {
Query: { ... },
};
```
But it falls short in certain scenarios, such as when resolver arguments are nullable. It still need improvement.
### Feature description
It is desirable to have a situation where appropriate type information is generated, allowing for comfortable writing of Plan Resolvers.
There are two possible ways:
- Document or include to `grafast` package a type that converts types generated by existing tools, as mentioned above(brush it up)
- Create a new tool or new plugin of graphql-codegen to generate type code for Grafast
### Motivating example
People writing Grafast Plan Resolvers in TypeScript
### Breaking changes
### Supporting development
I [tick all that apply]:
- [ ] am interested in building this feature myself
- [ ] am interested in collaborating on building this feature
- [x] am willing to help testing this feature before it's released
- [ ] am willing to write a test-driven test suite for this feature (before it exists)
- [ ] am a [Graphile sponsor](https://www.graphile.org/sponsor/) ❤️
- [ ] have an active [support or consultancy contract](https://www.graphile.org/support/) with Graphile
Contributor guide
Assessment
This issue has not been assessed yet.