resolveType on unions and itnerface from type-graphql ignored when using code first approach
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return one of multiple object types. Union type.
Read more >type-graphql/Lobby - Gitter
Hi, I'm trying to define input type for a resolver, but it returns "can't determine graphql input type for items", here is a...
Read more >GraphQL.js - use Interface as a default (fallback) type in ...
GraphQL is strongly typed and doesn't support generics or some kind of "fallback" mechanism when resolving unions and interfaces.
Read more >Abstract Types - GraphQL Nexus
resolveType return type will be typed as a union of string literals matching the GraphQL object type names of all members in the...
Read more >Resolvers - TypeGraphQL
First you have to create a resolver class and annotate it with @Resolver() ... Then you can create class methods which will handle...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
)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
)