When and How to use GraphQL with Microservice Architecture

前端 未结 9 1179
遇见更好的自我
遇见更好的自我 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:46

    To question 1, Intuit acknowledged the power of GraphQL few years back when it announced moving to One Intuit API ecosystem (https://www.slideshare.net/IntuitDeveloper/building-the-next-generation-of-quickbooks-app-integrations-quickbooks-connect-2017). Intuit chose to go with approach 1. The drawback that you mention actually prevents developers from introducing breaking schema changes that could potentially disrupt client applications.

    GraphQL has helped improve productivity of developers in a number of ways.

    1. When designing a new microservice for a domain, engineers (backend/ frontend/ stakeholders) agree on a schema for the domain entities. Once the schema is approved, it is merged with the master domain schema (universal) and deployed on the Gateway.Front end engineers can start coding client applications with this schema while backend engineers implement the functionality. Having one universal schema means that there are no two microservices with redundant functionality.
    2. GraphQL has helped client applications become simpler and faster. Want to retrieve data from /update data to multiple microservices? All client applications have to do is fire ONE GraphQL request and the API Gateway abstraction layer will take care to fetch and collate data from multiple sources (microservices). Open source frameworks like Apollo (https://www.apollographql.com/) have accelerated the pace of GraphQL adoption.

    3. With mobile being the first choice for modern applications, it is important to design for lower data bandwidth requirements from ground zero. GraphQL helps by allowing client apps to request for specific fields only.

    To question 2: We built a custom abstraction layer at the API Gateway that knows which part of the schema is owned by which service (provider). When a query request arrives, the abstraction layer forwards the request to the appropriate service(s). Once the underlying service returns the response, the abstraction layer is responsible to return the requested fields.

    However, today there are several platforms out there (Apollo server, graphql-yoga, etc.) that allow one to build a GraphQL abstraction layer in no time.

提交回复
热议问题