Search code examples
node.jstypescriptgraphqlnestjsapollo

NestJS Issue with resolver, throwing undefined


need a little help. I'm creating a mutation and it's throwing below error,

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

Please find the resolver,

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 I'm creating a class with @InputType() to accept arguments with mutation, looks like this,

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

and here's the service layer,

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);
    }
}

while running it, I'm getting the output of this from resolver level.

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

can anyone please help me to understand the reason of the above mentioned error.


Solution

  • I think this might be the same issue with as

    NestJS - Injected service is undefined in the constructor

    and emitDecoratorMetadata and its importance in transpiled code

    make sure there's emitDecoratorMetadata in your tsconfig.json and it's true
    Nest need the meta data from decorator for the injection mechanism to work correctly