Connect related distributed nestjs graphql microservices

13 Views Asked by At

Just started to get my hands into graphql with nestjs. I have created two graphql microservices that i would like to call each other to get bigger graph of the capabilities of the system. Background: User graph is built when querying with UserId and Region. Applications graph is built when querying with Username, Email. Right now here is how the model looks

User Request

UserRequest{
 UserId: string;
 Region: string;
}

User Graph Response

User {
 Username: string;
 Email: string[];
 Firstname: string;
}

Application Request

ApplicationRequest {
  Username: string;
  Email: string[];
}

Application Response

Application {
 Company: string;
 Region:string;
 Position:string;
}

Problem here is that i am not sure how to go about composing a response to get Users along with their applications. I did read about federation using apollo federation, but all of the examples are just plain simple like they are related to each other by just ID. In my case i can only get applications when users username and array of email address is given. But to get that i will need to query user graph again. How do i create a solution such that i do below i get desired response below. User Request

UserRequest{
 UserId: string;
 Region: string;
}

UserResponse {
 Username: string;
 Email: string[];
 Firstname: string;
 Applications: Application[]
}
0

There are 0 best solutions below