dotansimha / dotansimha/graphql-code-generator
FieldWrapper not applied to fields in union resolver type
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Hi! First thanks to @dotansimha for his great effort on this project!
**Describe the bug**
I've run into a bit of an issue with a circular type definition in a union field, a custom field wrapper and the `typescript-resolvers` plugin. I would expect the `parent` field in the example below to be wrapped with `FieldWrapper` like it is the original type. As I'm using the same resolver(that looks like my `FieldWrapper` type) for two separate generated types, this currently results in a type error when using the generated `ResolverTypes` directly. A workaround is to override the `Comment` type with a mapper.
**To Reproduce**
Repo: https://codesandbox.io/s/exciting-bhaskara-s9qze
Steps to reproduce the behavior:
1. My GraphQL schema:
```graphql
type Query {
comment(id: ID!): Comment!
}
union CommentParent = Comment
type Comment {
id: ID!
parent: CommentParent!
}
```
2. My GraphQL operations:
```graphql
# No operations
```
3. My `codegen.yml` config file:
```yml
schema: schema.graphql
documents: {}
generates:
types.ts:
plugins:
- typescript
- typescript-resolvers
config:
wrapFieldDefinitions: true
fieldWrapperValue: |
T | Promise | ((args: unknown, context: GraphQLContext, info: GraphQLResolveInfo) => Promise | T)
```
**Expected behavior**
A field that does get resolved to another resolver type should also be wrapped with the custom field wrapper.
I would expect this
```typescript
type ResolversTypes = {
Comment: ResolverTypeWrapper & { parent: FieldWrapper }>;
CommentParent: ResolversTypes['Comment'];
}
```
as opposed to the original:
```typescript
type ResolversTypes = {
Comment: ResolverTypeWrapper & { parent: ResolversTypes['CommentParent'] }>;
CommentParent: ResolversTypes['Comment'];
}
```
**Environment:**
- @graphql-codegen/add 2.0.2
- @graphql-codegen/cli 1.20.1
- @graphql-codegen/typescript 1.21.0
- @graphql-codegen/typescript-resolvers 1.19.0
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.