ResolveProperty('__resolveType') not working with type-graphql
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:26 (8 by maintainers)
Top 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 >
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
See https://typegraphql.ml/docs/interfaces.html
@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 totarget: es6
.