Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldWrapper not applied to fields in union resolver type #5776

Open
Tracked by #8296 ...
matthiaskern opened this issue Mar 31, 2021 · 2 comments
Open
Tracked by #8296 ...

FieldWrapper not applied to fields in union resolver type #5776

matthiaskern opened this issue Mar 31, 2021 · 2 comments
Labels
core Related to codegen core/cli help wanted Extra attention is needed stage/1-reproduction A reproduction exists

Comments

@matthiaskern
Copy link

matthiaskern commented Mar 31, 2021

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:
type Query {
    comment(id: ID!): Comment!
}

union CommentParent = Comment

type Comment {
    id: ID!
    parent: CommentParent!
}
  1. My GraphQL operations:
# No operations
  1. My codegen.yml config file:
schema: schema.graphql
documents: {}
generates:
  types.ts:
    plugins:
      - typescript
      - typescript-resolvers
    config:
      wrapFieldDefinitions: true
      fieldWrapperValue: |
        T | Promise<T> | ((args: unknown, context: GraphQLContext, info: GraphQLResolveInfo) => Promise<T> | 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

type ResolversTypes = {
  Comment: ResolverTypeWrapper<Omit<Comment, 'parent'> & { parent: FieldWrapper<ResolversTypes['CommentParent']> }>;
  CommentParent: ResolversTypes['Comment'];
}

as opposed to the original:

type ResolversTypes = {
  Comment: ResolverTypeWrapper<Omit<Comment, 'parent'> & { 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

@limulus
Copy link

limulus commented Aug 8, 2021

@matthiaskern Were you able to find a workaround for this, by chance? The only thing I have really been able to come up with is to avoid type checking with the Resolvers type, which obviously is not ideal.

@matthiaskern
Copy link
Author

@limulus It's been a while, but I believe using mappers to the original resolver type to have alleviated the issue at the time, e.g.

      mappers:
        Comment: Comment

@dotansimha dotansimha added the help wanted Extra attention is needed label Sep 6, 2021
@charlypoly charlypoly added stage/1-reproduction A reproduction exists and removed bug/2-confirmed labels Mar 14, 2022
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli help wanted Extra attention is needed stage/1-reproduction A reproduction exists
Projects
None yet
Development

No branches or pull requests

4 participants