dotansimha / dotansimha/graphql-code-generator
[typescript-resolvers] Allow passing parent types to `Resolvers`
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
## Problem
We use this wonderful tool together with `@graphql-utilities/schema` to generate type safe mocks for our UI component stories. In those stories, we've given developers the ability to mock the GraphQL schema by passing in resolvers. These resolvers might have different parent types depending on what the developer is presenting in the story. At the moment, it's only possible to generate resolver types with specific parent types or overridable parent types via `allowParentTypeOverride`. Unfortunately, this means that each resolver needs to have types added, though. Also, allowParentTypeOverride is just for the generics and doesn't change the valid types that can be returned from a resolver and one might want to return a different type like when using mappers.
## Solution/Request
It would be great if when using `Resolvers` we could pass `ResolversParentTypes`. It would look something like this:
```typescript
const resolvers: Resolvers
```
Internally, `Resolvers` would replace the parent types given and fall back to the current behavior when a type is missing. This could be done like this:
```typescript
type Resolvers = {
// ...
User?: UserResolvers & TResolverParentTypes)['User']
// ...
}
```
A similar change would be needed for type resolvers where the mappers are also able to be inferred from this second generic of `Resolvers`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.