Hope you'll doing great
I'm trying to create a gateway for a Grpc service built with Nestjs and it's running correctly but I can't make the gateway connect to it, I read the documentation and follow the exact instruction there but still i got the same error and here is my code:
// speciality.service.ts
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import {
Specialities,
specialityServiceInterface,
} from './interface/services.interface';
import { Observable } from 'rxjs';
@Injectable()
export class SpecialityService implements OnModuleInit{
private spicilaityService: specialityServiceInterface;
constructor(@Inject('SpecialityResolver') private client: ClientGrpc){}
onModuleInit() {
this.spicilaityService = this.client.getService<specialityServiceInterface>('SpecialityResolver');
}
async getAll(): Promise<Observable<Specialities>> {
return await this.spicilaityService.getSpecialities();
}
}
I'm not sure what is Observable exact job is also
Here is the interface for this service
import { Observable } from "rxjs";
export interface SpecialityInput {
name: string;
name_ar: string;
}
export interface SpecialityType {
id: string;
name: string;
name_ar: string;
}
export interface Specialities {
specialities: [SpecialityType]
}
export interface SubSpecialityInput {
SpecialityId: string;
name: string;
name_ar: string;
}
export interface SubSpeciality {
SpecialityId: string;
name: string;
name_ar: string;
}
export interface SubSpecialityType {
id: string;
SpecialityId: string;
name: string;
name_ar: string;
}
export interface SubSpecialities {
subSpecialities: [SubSpeciality]
}
export interface specialityServiceInterface {
getSpecialities(): Promise<Observable<Specialities>>
getSubSpecialities(): Promise<Observable<SubSpecialities>>
createSpeciality(data: SpecialityType): Promise<Observable<SpecialityType>>
createSubSpeciality(data: SubSpecialityType): Promise<Observable<SubSpecialityType>>
}
Hope this little information can help you understand the error
I should be able to get a response from a MongoDB exactly like the nest schema:
export interface SpecialityType {
id: string;
name: string;
name_ar: string;
}
export interface Specialities {
specialities: [SpecialityType]
}