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

resolveType on unions and itnerface from type-graphql ignored when using code first approach #231

Closed
vnenkpet opened this issue May 2, 2019 · 7 comments

Comments

@vnenkpet
Copy link

vnenkpet commented May 2, 2019

Describe the bug
When I try defining a resolveType function on createUnionType, it compiles succesfully but I'm getting this warning:

Type "MyUnionType" is missing a "__resolveType" resolver. Pass false into "resolverValidationOptions.requireResolversForResolveType" to disable this warning.

The type then really isn't working and complains with this:

Abstract type MyUnionType must resolve to an Object type at runtime for field UserType.myUnion (...)

To Reproduce

export const MyUnionType = createUnionType({
  name: 'MyUnionType',
  types: [PersonType, PlaceType],
  resolveType: value => {
    if (value instanceof PersonEntity) {
      return PersonType;
    }
    if (value instanceof PlaceEntity) {
      return PlaceType;
    }
    return undefined;
  },
});

(I didn't test if the resolveType method itself works properly, but that's unrelated to this issue as it's obviously ignored - definitely doesn't get called).

Expected behavior
This should work and resolve into the proper type at runtime.

Enviorment

  • OS: MacOS
  • Node 12.1.0
  • Package version 0.17.3
  • TypeScript version 3.4.2
  • @nestjs/graphql version 6.0.5
@vnenkpet
Copy link
Author

vnenkpet commented May 2, 2019

Asked in MichalLytek/type-graphql#326 already, apparently out of their scope so I suppose it belongs here. It's a new feature in type-graphql but I think it would be nice to have it here.

@kamilmysliwiec
Copy link
Member

It should be fixed in the @next version ($ npm i @nestjs/graphql@next). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/core@6.2.0)

@kamilmysliwiec
Copy link
Member

Published as 6.2.0 ($ npm i @nestjs/graphql@latest). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/core@latest)

@pereslavtsev
Copy link

pereslavtsev commented Aug 30, 2019

@kamilmysliwiec still reproducible, I have latest versions @nestjs/graphql 6.4.3 and type-graphql 0.17.5

@Logic-Bits
Copy link

can confirm - CustomFieldConfigUnion doesnt work.
in my case the unionMetadata.classTypes is empty and throws error at buildTypesInfo() in schema-generator.js

@JazzShapka
Copy link

resolveType for createUnionType still doesn't work. Are there any other solutions?

@lock
Copy link

lock bot commented May 5, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants