question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kamilmysliwieccommented, May 11, 2019

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)

1reaction
kamilmysliwieccommented, May 14, 2019

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found