When and How to use GraphQL with Microservice Architecture

前端 未结 9 1038
遇见更好的自我
遇见更好的自我 2021-01-29 17:13

I\'m trying to understand where GraphQL is most suitable to use within a Microservice architecture.

There is some debate about having only 1 GraphQL schema that works as

9条回答
  •  迷失自我
    2021-01-29 17:40

    The way it is being described in this question, I believe that using a custom API gateway as an orchestration service can make a lot of sense for complex enterprise focused applications. GraphQL can be a good technology choice for that orchestration service, at least as far as querying goes. The advantage to your first approach (one schema for all microservices) is the ability to stitch together the data from multiple microservices in a single request. That may, or may not, be very important depending on your situation. If the GUI calls for rendering data from multiple microservices all at once, then this approach can simplify the client code such that a single call can return data that is suitable for data binding with the GUI elements of such frameworks as Angular or React. This advantage doesn't apply for mutations.

    The disadvantage is tight coupling between the data APIs and the orchestration service. Releases can no longer be atomic. If you refrain from introducing backwards breaking changes in your data APIs, then this can introduce complexity only when rolling back a release. For example, if you are about to release new versions of two data APIs with the corresponding changes in the orchestration service and you need to roll one of those releases back but not the other, then you will be forced to roll back all three anyway.

    In this comparison of GraphQL vs REST you will find that GraphQL is not quite as efficient as RESTful APIs so I would not recommend replacing REST with GraphQL for the data APIs.

提交回复
热议问题