GraphQL Mesh for Improving Engineer’s Productivity
We were a new team developing an app for salesman named Sales Pintar. At the beginning of Sales Pintar, we need to create our own infrastructure based on Warung Pintar’s standard. One of the rule to follow is the use of GraphQL which have become a standard of communication between client and server.
The existing GraphQL server used by Warung Pintar require engineer to write code in 2 projects. First, every team will create their own backend service which could be REST API or gRPC. Then, they have to add their GraphQL Schema in GraphQL server repository and also create resolver to handle request from client. GraphQL server acts as a gateway to redirect any request to their backend service respectively. As the project become larger, some of backend engineers start to feel that the process is burdensome and could be more efficient.
After discussions with Staff Engineer, we decided to solve the existing problem by using GraphQL Mesh in Sales Pintar. GraphQL Mesh is a GraphQL server which allows access to any source of data using graphql query. We can connect to REST API, MySQL, SOAP API, Mongo DB, or even another GraphQL API just by adding a configuration file. There is no need for engineers to define GraphQL Schema and resolvers by themselves, it will be generated automatically by GraphQL Mesh.
The example above shows GraphQL Mesh connected to a REST API. We add the connection config in .meshrc.yaml
and we also need to add endpoint specification in get-all-salesman.JSON
. This endpoint spec will be used by GraphQL Mesh as a contract to generate GraphQL Schema. It can be even easier if you have defined OpenAPI Spec for your API. You just need to use this plugin grapql-mesh/openapi and get going.
As a result, backend engineers who build API using GraphQL Mesh feel their productivity increase and it becomes so much easier to work on it in daily basis. Apart from the good thing, we also faced some difficulties while using GraphQL Mesh. There were times when suddenly it stopped working and it turned out we needed to update the version. At that time, the documentation were not as good as it is now and there weren’t many articles talked about GraphQL Mesh which made it a little harder to solve problems.
Big thanks to Zeihan, Andre Sudi, Kevin, Oky, Yuri, Hengky, and Ramadhan who gave so much in this project. We have a really amazing time with GraphQL Mesh and we hope you can try this too, good luck!