GraphQL-focused open source group The Guild has shared its newest project, GraphQL Mesh, with the world, promising devs a way to use the query language for data access in all sorts of APIs – not just those running it.
According to the group, which also takes care of projects such as GraphQL CLI and GraphQL Inspector, “the goal of GraphQL Mesh is to let developers easily access services that are written in other APIs’ specs (such as gRPC, OpenAPI, Swagger, oData, SOAP, and also GraphQL) with GraphQL queries and mutations.” The services apparently don’t have to be changed in the process and Mesh is supposed to be able to run anywhere as an SDK.
The list of possible use cases for now includes scenarios in which data is meant to be aggregated, transformed, and linked across multiple APIs or accessed and fetched across microservices without having to rely on single services that could become a central point of failure. GraphQL Mesh is also meant as a way of offering a type-safe querying option for legacy APIs.
Once installed, the project can act as a data proxy, using common libraries to wrap other API services. The Mesh readme states that “You can use this proxy locally in your service or application by running the GraphQL schema locally (with GraphQL execute), or you can deploy this as a gateway layer to your internal service.”
Under the hood, the project collects API schema specifications from services, creates a runtime instance of a “fully-typed SDK” for the latter, and converts API specifications into the GraphQL schema. Since this can prove quite tricky, with all the different approaches APIs use, the project mostly draws on the openapi-to-graphql library for that. Afterwards, custom schema transformations and extensions are used, and a fully-typed, single schema, GraphQL SDK to fetch data from the services is created.
Currently, GraphQL Mesh supports GraphQL endpoints, Swagger and version 2 and 3 of the OpenAPI specification, JSON schema structures for requests and responses, Postgres database/gRPC/protobuf schemas, the SOAP specification, and a Mongoose schema wrapper. Work on support for Apollo Federation services, and OData specifications is meanwhile still in progress.
In fact, the whole project should be considered in progress (at the time of writing, builds were currently failing), so there will surely be lots of breaking changes before the project can be unleashed into production – even though The Guild claims Mesh already being “a huge upgrade for us and our clients”.