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.

ResolveProperty('__resolveType') not working with type-graphql

See original GitHub issue

The last few days I migrated our project to use type-graphql with nest. I managed to migrate everything, but I am still stuck on one thing. Providing a custom __typename doesn’t seem to work.

Here is my resolver:

@Resolver(ServiceProvider)
export class ServiceProviderResolvers {
    constructor(private readonly searchService: SearchService) {}

    @Query(() => [ServiceProvider])
    all(): Promise<ServiceProvider[]> {
        return this.searchService.all();
    }

    @ResolveProperty('__resolveType')
    resolveType(obj: ServiceProvider): string {
         return obj.type;
    }

    @ResolveProperty()
    test(obj: ServiceProvider): string {
         return obj.type;
    }
}

But the resolveType doesn’t seem to be called, where test method is called if I query for test field.

I also tried to use some interface like suggested 19majkel94 (from type-graphql) but still doesn’t work: https://github.com/19majkel94/type-graphql/issues/181#issuecomment-475166589

Is there any way to customize __typename with nest using type-graphql?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:26 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Mar 28, 2019
1reaction
michelcvecommented, Apr 25, 2019

@kamilmysliwiec While creating a test project, I finally figured it out.

In my tsconfig.json I had target: es5. This works fine, until you start using @ResolveProperty. The resolution for this is switching target to target: es6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers
This feature is useful when the field is purely calculable (eg. averageRating from ratings array) and you don't want to pollute the class...
Read more >
graphql-modules not calling __resolveType - node.js
I'm having the same issue, can confirm that it appears __resolveType is never called when using graphql-modules. I'm going to raise an issue ......
Read more >
Resolvers | NestJS - A progressive Node.js framework
To declare that an array's items (not the array itself) are nullable, set the nullable property ... This will be clear as we...
Read more >
Constructing Types with the GraphQL Package
Finally, we have a resolve property with the resolver to return what we ... Note that we have an array of types and...
Read more >
type-graphql
TypeGraphQL comes to address these issues, based on experience from a few years of developing GraphQL APIs in TypeScript. The main idea is...
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