Closed lparolari closed 2 years ago
After diving a bit into the problem and reading this illuminating issue https://github.com/nestjs/graphql/issues/226, I found that my problem is due to this portion of code
and in particular to
where, as the error message says, I'm not providing an explicit type for "user".
Fix
Import the user model and add the type explicitly to the decorator for the user method.
import { User } from '../../models/user.model';
@ResolveField('user', (of) => User) // <-- modify this
async user(@Parent() auth: Auth) {
return await this.auth.getUserFromToken(auth.accessToken);
}
@lparolari thanks for raising this issue. This project uses NestJS CLI Plugin to generate the GraphQL types, hence the type in @ResolveField('user')
is not needed during the build step. However, jest is testing against the typescript and not invoking the CLI Plugin.
I found the following issue and a blog post on those topics.
Let me know if that helps you.
@marcjulian Thank you a lot! I followed the issue you reported and worked like a charm. Do you think that is useful to add this trick to the project or am I using something in a wrong way?
@lparolari yes it very useful to add this trick to this starter project. Do you mind creating a PR?
@marcjulian Sure, just did it. I hope it might help.
Bug
Steps to reproduce
Expected behaviour
e2e tests passed
Actual behaviour
How can I fix this? Thank you!