Skip to content

Error "Cannot find name 'User'" in typescript-resolvers output #5841

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

Closed
Tracked by #8296 ...
dariusj18 opened this issue Apr 14, 2021 · 3 comments
Closed
Tracked by #8296 ...

Error "Cannot find name 'User'" in typescript-resolvers output #5841

dariusj18 opened this issue Apr 14, 2021 · 3 comments
Labels
core Related to codegen core/cli kind/bug Bug :-( stage/1-reproduction A reproduction exists stage/2-failing-test A failing test was created that describes the issue

Comments

@dariusj18
Copy link

Describe the bug
I am just getting used to typescript/graphql etc, so my terminology might not be so good, however I get an error with the resulting type definitions when using the typescript-resolvers plugin with the typesPrefix set and enumPrefix set to false. My guess is I misunderstood the intent of the enumPrefix option, or there is a bug.

To Reproduce
Steps to reproduce the behavior:

https://codesandbox.io/s/beautiful-smoke-1c1x2?file=/types.ts

Expected behavior
The resolver would use the type name with the prefix.

Environment:

  • OS: Windows
  • @graphql-codegen/...:
    @graphql-codegen/typescript
    @graphql-codegen/typescript-operations
    @graphql-codegen/typescript-resolvers
  • NodeJS: 14.16.0
@dariusj18
Copy link
Author

As you can see in the resulting types, the following block

export type IResolversTypes = ResolversObject<{
  Query: ResolverTypeWrapper<{}>;
  Int: ResolverTypeWrapper<Scalars["Int"]>;
  User: ResolverTypeWrapper<User>;
  String: ResolverTypeWrapper<Scalars["String"]>;
  Boolean: ResolverTypeWrapper<Scalars["Boolean"]>;
}>;

/** Mapping between all available schema types and the resolvers parents */
export type IResolversParentTypes = ResolversObject<{
  Query: {};
  Int: Scalars["Int"];
  User: User;
  String: Scalars["String"];
  Boolean: Scalars["Boolean"];
}>;

I would assume the User type should be IUser

@obedm503
Copy link

obedm503 commented Sep 9, 2021

Having the same issue. A workaround until this is fixed is to manually define it in your mappers

generates:
  path/to/generated/types.ts:
    config:
      mappers:
        User: IUser

@charlypoly charlypoly added stage/2-failing-test A failing test was created that describes the issue and removed bug/1-repro-available labels Mar 14, 2022
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
@eddeee888
Copy link
Collaborator

This looks fixed in the later versions. Please open another issue if it's still a problem.
Example sandbox with the correct generated type.

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 kind/bug Bug :-( stage/1-reproduction A reproduction exists stage/2-failing-test A failing test was created that describes the issue
Projects
None yet
Development

No branches or pull requests

5 participants