0

Suppose I am building a system in a microservices architecture. Instead of using Rest, I chose GraphQL. Thus, I have several services that have no controllers but resolvers.

Now I would like to call a method from service2 (microservice) in the service1 (microservice) and get the result from the service2.

Normally, I could use a Hybrid application in NestJs with @MessagePattern. Nevertheless, when using GraphQL, the reference must be to query or mutaion in Service 2's Resolver.

So how with this arrangement to establish a connection between services 1 and 2 using resolvers?

g_m
  • 456
  • 1
  • 3
  • 12

1 Answers1

1

It sounds like what you want is schema stitching. This will allow you to add remote schemas (essentially methods from other services) to your graphQL server.

I'm more familiar with C# implementations of GraphQL e.g. ChilliCream Hot Chocolate which has info on schema stiching here: https://chillicream.com/docs/hotchocolate/distributed-schema/schema-stitching

Since you mentioned NestJs in your question, I'll link this previous stack overflow question in: How to get multiple remote schemas stitched with Nestjs and apollo server

YungDeiza
  • 3,128
  • 1
  • 7
  • 32
  • If I undestund the Stitching remote schemas correctly, it is dedicated to create a Gateway to merge many subgraphs as a singe entry point? My expectation was rather to simple call like fetch not the merging of subgraphs. Additionally, my invocation to Microservice2 should be in Service, not in Resolver, and that probably isn't explained. I'm stuck on it and don't know how to do it right :( – g_m Jul 16 '22 at 08:29
  • Maybe I shoud use fetch insted? https://www.apollographql.com/blog/graphql/examples/4-simple-ways-to-call-a-graphql-api/#d58d – g_m Jul 16 '22 at 08:35
  • Not quite sure if I'm understanding what you mean but I think you can set up schems stitching to allow methods in service y to be called from service x but also still call the methods from service y directly. – YungDeiza Jul 16 '22 at 21:28