NestJS 解析器出现问题,抛出未定义的问题

问题描述 投票:0回答:1

需要一点帮助。我正在创建一个突变,它抛出以下错误,

 ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'entryUser')

请找到解析器,

export class UsersResolver {

    constructor(private userService:UsersService) {}

    @Mutation((returns) => User)
    entry(@Args('entryData') entryData: EntryUserInputType) {
        console.log("======> ", entryData);
        return this.userService.entryUser(entryData);
    }
}

as

EntryUserInputType
我正在创建一个带有
@InputType()
的类来接受带有突变的参数,看起来像这样,

mutation{
  entry(entryData: {
    mobile: "9038897580"
  }) {
    id
  }
}

这是服务层,

export class UsersService {
    constructor(@InjectRepository(User) private userRepo: Repository<User>) {}

    async entryUser(enterUserData: EntryUserInputType) {
        const query = {
            where: {
                mobile: enterUserData.mobile
            }
        }
        const checkIfUserExist = await checkIfUserExists(this.userRepo, enterUserData, query);
        console.log("=======> ", checkIfUserExist);
    }
}

运行它时,我从解析器级别获取其输出。

[Object: null prototype] { mobile: '9038897580' }

任何人都可以帮我理解上述错误的原因吗?

node.js typescript graphql nestjs apollo
1个回答
0
投票

我认为这可能是与 as 相同的问题

NestJS - 构造函数中未定义注入的服务

emitDecoratorMetadata 及其在转译代码中的重要性

确保您的

emitDecoratorMetadata
中有
tsconfig.json
并且它是
true

Nest 需要来自装饰器的元数据才能使注入机制正常工作

© www.soinside.com 2019 - 2024. All rights reserved.