Nest can’t resolve dependencies of the MessageResolver (?, PubSub)

Nest can’t resolve dependencies of the MessageResolver (?, PubSub)


0

message.module.ts:

import { Module, forwardRef } from '@nestjs/common';
import { MessageResolver } from './message.resolver';
import { MessageService } from './message.service';
import { MongooseModule } from '@nestjs/mongoose';
import { Message, MessageSchema } from './models/message.model';
import { UserModule } from 'src/user/user.module';
import { GroupModule } from 'src/group/group.module';
import { PubSub } from 'graphql-subscriptions';

@Module({
  imports: [
    MongooseModule.forFeature([{ name: Message.name, schema: MessageSchema }]),
    forwardRef(() => UserModule),
    GroupModule,
  ],
  providers: [MessageResolver, MessageService, PubSub],
  exports: [MessageService],
})
export class MessageModule {}

message.resolver.ts:

import { PubSub } from 'graphql-subscriptions';
import { MessageService } from './message.service';
import { Inject } from '@nestjs/common';
import { Resolver, Query, Mutation, Args } from '@nestjs/graphql';
import { Message } from './models/message.model';
import { CreateMessageInput } from './dto/message.input';

@Resolver((of) => Message)
export class MessageResolver {
  constructor(
    @Inject('MessageService')
    private readonly service: MessageService,
    @Inject('PubSub') private readonly pubSub: PubSub,
  ) {}

  @Query((returns) => [Message])
  async getMessagesByUserId(
    @Args('userId', { type: () => String }) userId: string,
  ): Promise<Message[]> {
    return this.service.getMessagesByUserId(userId);
  }

  @Mutation((returns) => Message)
  async createMessage(
    @Args('createMessageInput') createMessageInput: CreateMessageInput,
  ): Promise<Message> {
    const newMessage = this.service.create(createMessageInput);
    this.pubSub.publish('messageAdded', { messageAdded: newMessage });

    return newMessage;
  }
}

enter image description here

I wrote a chat application and it is integrated with Nest and GraphQL.
Now I want to add the resolvers of the message module, but it gives this error

Share
Improve this question

New contributor

AmirAli Eidivandi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 7 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *