Support @Resolver without type name or class (code first)
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Application throw the following error when using @Resolver()
without specifying any type name or type class:
TypeError: Cannot read property 'prototype' of undefined
Caused by: https://github.com/nestjs/graphql/blob/master/lib/decorators/resolvers.decorators.ts#L250
Expected behavior
No error should be thrown.
Minimal reproduction of the problem with instructions
Sorry for my poor english, here is a test case to reproduce the issue: https://github.com/zhenwenc/nest-graphql-issues/blob/master/test/resolver-without-type-name.spec.ts
Environment
Nest version: 6.0.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >Code-first vs. schema-first development in GraphQL
We review and compare the two approaches to creating a GraphQL service — code-first and schema-first — and take a stance on which...
Read more >Resolvers | NestJS - A progressive Node.js framework
In the code first method, a resolver class both defines resolver ... indicate which class is the parent type (i.e., the corresponding ObjectType...
Read more >Resolvers – GraphQL Tools
Writing resolvers with graphql-tools. ... Class Method Resolvers ... the type name as a string from __resolveType is only supported starting ...
Read more >c# - Resolve Type from Class Name in a Different Assembly
Type.GetType("MyProject.Domain.Model." + myClassName);. This works great if the code that is performing this action 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
@zhenwenc I have happen to stumble upon the very same issue when using @ResolveProperty() decorator and what solved for me was to properly annotate the Resolver as per docs using Type not string name so for example in your case:
❌
@Resolver('SampleObject')
✅@Resolver(of => SampleObject)
So in your test simply change the annotation as specified above and all should work as expected.
Hope it helps! Tom
Well, you’re right. Thanks for reminding me 😃