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

resolver: Using {T} in a custom mapper loses Omits #9043

Closed
ryanrhee opened this issue Feb 22, 2023 · 2 comments · Fixed by #9110
Closed

resolver: Using {T} in a custom mapper loses Omits #9043

ryanrhee opened this issue Feb 22, 2023 · 2 comments · Fixed by #9110
Assignees
Labels
kind/bug Bug :-( plugins stage/1-reproduction A reproduction exists

Comments

@ryanrhee
Copy link

ryanrhee commented Feb 22, 2023

Which packages are impacted by your issue?

@graphql-codegen/cli, @graphql-codegen/typescript-resolvers

Describe the bug

When using a custom mapper with {T}, the recursive definition is lost, and the default type from the typescript package is used instead.

#1631 says that {T} should be the recursive definition.

Your Example Website or App

https://codesandbox.io/s/reverent-snowflake-7npr0h?file=/codegen.ts

Steps to Reproduce the Bug or Issue

  1. Run yarn generate in a codesandbox terminal
  2. Read types.ts's ResolverTypes["Post"] (line 119), note the definition which is ResolverTypeWrapper<Omit<Post, 'authorEdge'> & { authorEdge: ResolversTypes['UserEdge'] }>
  3. Go to codegen.ts and change the config by uncommenting line 11 so that Post gets a custom mapper
  4. Re-run yarn generate
  5. Read the same type in types.ts, and note that the new type is now ResolverTypeWrapper<Omit<Post, 'tags'>>.

Expected behavior

At step 5, I expect the type to be:

ResolverTypeWrapper<Omit<Omit<Post, 'authorEdge'> & { authorEdge: ResolversTypes['UserEdge'] }, 'tags'>

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 16.16.0
  • graphql version: 16.6.0
"@graphql-codegen/cli": "2.16.3",
"@graphql-codegen/typescript": "2.7.1",
"@graphql-codegen/typescript-resolvers": "^2.7.3",

Codegen Config File

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "schema.graphql",
  documents: "document.graphql",
  generates: {
    "types.ts": {
      config: {
        mappers: {
          UserEdge: "Omit<{T}, 'user'>"
          // Post: "Omit<{T}, 'tags'>"
          // Post is `ResolverTypeWrapper<Omit<Post, 'authorEdge'> & { authorEdge: ResolversTypes['UserEdge'] }>`
          // when mapper is not specified.
          //
          // I expect that whole type to replace `{T}`.
          //
          // However, the type after mapper specification is
          // `Omit<Post, 'tags'>` which loses the `authorEdge` mapped type.
        }
      },
      plugins: ["typescript", "typescript-resolvers"]
    }
  }
};

export default config;

Additional context

No response

@ryanrhee ryanrhee changed the title Using {T} in a custom mapper loses Omits resolver: Using {T} in a custom mapper loses Omits Feb 22, 2023
@saihaj saihaj added stage/1-reproduction A reproduction exists plugins kind/bug Bug :-( labels Feb 23, 2023
@saihaj
Copy link
Collaborator

saihaj commented Mar 7, 2023

@graphql-codegen/cli@3.2.2

@ryanrhee
Copy link
Author

ryanrhee commented Mar 8, 2023

Just tested out 3.2.2, and can confirm the bug is fixed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Bug :-( plugins stage/1-reproduction A reproduction exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants