Illustration: GraphQL Mesh
By: Hiro Osaki
Tags: Docker, MySQL, Postgresql, GraphQL

Illustration: GraphQL Mesh

The quickest way to start GraphQL for non-JS person

Photo by Cody Board on Unsplash

How to get to GraphQL world. Gateway is here.

GraphQL’s hurdle for non-JS person

Go for it!

GraphQL is one of cutting edge API specification. GraphQL has built-in query format unlike REST API. This query format enables clients to control response contents. This means many performance advantages such as avoiding overfetch (larger response contents than you expected) and avoiding underfetch (smaller response contents than you expected).

We can adopt GraphQL by using many useful GraphQL tools like Apollo, Prisma, Hasura and so on. It is not so difficult.

But I found a hurdle for adopting GraphQL. This is the fact that most of GraphQL tools came from Node.js developer world. For example, Apollo server is one of the most popular GraphQL servers. Apollo runs as Node.js server. You need to know Node.js, npm or yarn command, package.json … This is natural because GraphQL was born in web services like Facebook, and these use JavaScript intensively.

Do you really need to know Node.js?

One of the most confusing parts is that GraphQL is web service interface as well as a query language to data source. What if you were a backend service engineer like database architect? You would have experience about SQL and JDBC so much. But possibly you would never have touched Node.js. In this case, GraphQL is a possible data query language but skillset and development tools required for GraphQL are totally different from those for existing database.

New way to adopt GraphQL: GraphQL Mesh

GraphQL Mesh shines here. GraphQL Mesh is an emerging tool for API conversion or API aggregation layer. Please refer to the creator’s article.

It supports existing APIs like GraphQL, OpenAPI, and many database interfaces like MySQL, PostgreSQL, Neo4J and so on. Then GraphQL Mesh automatically converts these data sources into GraphQL API.

In most case, GraphQL Mesh only requires YAML configuration .meshrc.yaml . GraphQL Mesh doesn’t need other configuration than data source address. For example, conversion from MySQL to GraphQL is like this

sources:

- name: Employees # Name of new GraphQL API

handler:

mysql: # Type of data source

host: your-mysql.com # Address of data source

port: 3306 # Port

user: root # Credential of data source

password: passwd # Credential of data source

database: employees # Database name

Configuration document and live samples is here. So simple!

Even for non-JS person, this is very easy to understand. This configuration looks much like the following JDBC configuration

mysql://root:passwd@your-mysql.com:3306/employees

So GraphQL Mesh is very promising way to start GraphQL without Node.js knowledge.

If you have a database such as PostgreSQL or Neo4J, GraphQL Mesh already has plugins to connect these data sources (PostgreSQL, Neo4J, MongoDB, SQLite, Apache Thrift)

You don’t need even a Node.js environment thanks to Docker

GraphQL Mesh itself runs as Node.js program. But you might want not to know Node.js at all. So you can use a docker container image which wrapped GraphQL Mesh. You only need to run with this command and access http://localhost:4000 . That’s it.

docker run --name mesh -p 4000:4000 -it --rm hiroyukiosaki/graphql-mesh:latest-all

You don’t even need a node.js environment including npm or yarn command. All you need is a machine in which docker was installed.

docker run --name mesh -p 4000:4000 -it --rm `pwd`/meshrc.yaml:/work/.meshrc.yaml hiroyukiosaki/graphql-mesh:latest-all

You can overwrite configuration file .meshrc.yaml with this command. Very simple.

Possibly the simplest use case.

You can also use helm to install GraphQL Mesh on Kubernetes.

helm repo add graphql-mesh https://onelittlenightmusic.github.io/graphql-mesh-docker/helm-chart

helm repo up

helm install my-graphql-mesh graphql-mesh/graphql-mesh

The details such as Helm chart parameters are described here.

Summary

For those that want to start GraphQL but don’t know much about Node.js, GraphQL Mesh is a killer component. All you have to prepare is your data source and configuration file for GraphQL Mesh called .meshrc.yaml .

If you have Docker environment, simply you can start GraphQL Mesh as a container. You don’t need to know Node.js at all.