Simple docker image to run just a GraphQL Mesh (Thank you Urigo and Mesh community for developing nice tool!)
Please prepare only Docker environment or Kubernetes and run the command. No need to understand Node.js.
- GraphQL Mesh Docker (supports Kubernetes/Helm)
- TL;DR
- Architecture
- Docker Images for GraphQL Mesh
- Run
- Customize
- Example
- Build on your own
# Run on Docker
docker run --name mesh -p 4000:4000 -it --volume ${PWD}/docker/work/.meshrc.yaml:/work/.meshrc.yaml --rm hiroyukiosaki/graphql-mesh:latest-all-alpine
# or run with docker-compose
cd docker && docker-compose up -d mesh-all-alpine
# or run on Kubernetes with helm
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
And access to http://localhost:4000
.
Run a query.
{
cases {
active
countryRegion
}
}
Data sources are databases like MySQL or PostgreSQL.
GraphQL Mesh can convert these data sources to GraphQL API.
GraphQL Mesh Docker runs GraphQL Mesh in Docker container. You can customize GraphQL Mesh settings by changing .meshrc.yaml
and mounting the file in Docker container (see Customize)
Tag | Description |
---|---|
latest (Dockerfile) |
Includes minimum CLI and handler (@graphql-mesh/openapi ) |
latest-alpine (Dockerfile) |
Alpine version for minimum footprint which includes minimum CLI and handler (@graphql-mesh/openapi ) |
latest-all (Dockerfile-all) |
Includes all handlers |
latest-all-alpine (Dockerfile-all) |
Alpine version for minimum footprint which includes all handlers |
You can choose step for your envionment (Docker or Kubernetes)
Simply run this command.
# Just docker run (choose tag version)
docker run --name mesh -p 4000:4000 -it --rm hiroyukiosaki/graphql-mesh:latest
docker run --name mesh -p 4000:4000 -it --rm hiroyukiosaki/graphql-mesh:latest-all
Alternatives
# docker-compose
docker-compose up -d mesh
# or to run vX.X.X-all
docker-compose up -d mesh-all
After running docker image, you can access to GraphQL Mesh service at http://localhost:4000
and you will see this screen.
There are two methods.
kubectl
helm
You need Kubernetes cluster.
If you don't have Kubernetes cluster, you can create Kubernetes on Docker with KinD
kind create cluster --name graphql --config kind-config.yaml
# If you want to change image, please edit k8s/pod.yaml
kubectl apply -f k8s/basic
# or
kubectl apply -f k8s/jsonschema-covid19
After the pod running, we can forward the kubernetes service port to local machine with this command and access to GraphQL Mesh at http://localhost:4000
.
kubectl port-forward svc/mesh-svc 4000:4000 &
# Add repository
helm repo add graphql-mesh https://onelittlenightmusic.github.io/graphql-mesh-docker/helm-chart
# Refresh repository
helm repo up
# Install helm chart into Kubernetes
helm install my-graphql-mesh graphql-mesh/graphql-mesh
# or install with parameter file
helm install my-graphql-mesh graphql-mesh/graphql-mesh -f <parameter-values.yaml>
Name | Description | Default |
---|---|---|
mountConfigMap.".meshrc.yaml" |
ConfigMap name containing .meshrc.yaml file |
None |
mountConfigMap."example-query.graphql" |
ConfigMap name containing example-query.graphql file |
None |
mountConfigMap."init.sh" |
ConfigMap name containing init.sh file. If it exists, container runs GraphQL Mesh after it runs init.sh |
None |
mount.".meshrc.yaml" |
inlined .meshrc.yaml file |
None |
mount."example-query.graphql" |
inlined example-query.graphql file |
None |
mount."init.sh" |
inlined init.sh file. If it exists, container runs GraphQL Mesh after it runs init.sh |
None |
replicaCount |
Count of replica pods | 1 |
image.repository |
Image repository | hiroyukiosaki/graphql-mesh |
image.tag |
Image tag | latest |
image.pullPolicy |
imagePullPolicy |
IfNotPresent |
imagePullSecrets |
Array of secret name | [] |
serviceAccount.create |
Create a ServiceAccount for GraphQL Mesh | true |
serviceAccount.name |
ServiceAccount name | "" |
serviceAccount.annotations |
Annotation structure for ServiceAccount | {} |
service.type |
Service type | ClusterIP |
service.port |
Service port | 80 |
service.annotations |
Annotation structure for Service | {} |
ingress.enabled |
Enable an Ingress | false |
ingress.annotations |
Annotation structure for Ingress | {} |
ingress.hosts.host |
Host name for Ingress | graphql-mesh.127.0.0.1.xip.io |
ingress.hosts.path |
Host path array for Ingress | [] |
resources |
Resource limits and requests (e.g. limits: { cpu: 100m, memory: 128Mi } ) |
{} |
Please refer to sample parameter values file for details.
There are two ways to customize GraphQL Mesh Docker.
- Customize
.meshrc.yaml
- Clone an existing example and run in Docker
-
Create your
.meshrc.yaml
. Please follow the guidance of the official document above. -
Place
.meshrc.yaml
in the current directory.- Go to
docker
directory. - Edit
docker-compose.yaml
file in order to point your.meshrc.yaml
and mount it to/work/.meshrc.yaml
volumes: - ./.meshrc.yaml:/work/.meshrc.yaml # <- comment out and point to your .meshrc.yaml
- Run
docker-compose up -d mesh
- Overwrite new ConfigMap resource file with this command.
kubectl create cm meshrc-cm --from-file .meshrc.yaml --dry-run -o yaml> k8s/basic/meshrc-cm.yaml
- Run
kubectl apply -f k8s/basic
Download sample values.yaml file and edit it to include your
.meshrc.yaml
mount: .meshrc.yaml: |- sources: - name: Ghibli handler: openapi: source: https://ghibliapi.herokuapp.com/swagger.yaml
- Go to
# This clones example and creates a directory "covid-mesh"
git clone https://github.com/jycouet/covid-mesh
# Mount this directory into container and run.
docker run --name mesh -p 4000:4000 -v `pwd`/covid-mesh:/work -it --rm hiroyukiosaki/graphql-mesh:v0.1.17 /bin/bash -c 'yarn install && yarn start'
The following use mysql-employee example.
Simpler docker-compose setup is here.
git clone https://github.com/datacharmer/test_db.git
# Run MySQL and restore employee db
docker run --name mysql -v `pwd`/test_db/:/test_db -e MYSQL_ROOT_PASSWORD=passwd -d -p 3306:3306 mysql --default-authentication-plugin=mysql_native_password
docker exec -it mysql /bin/bash
$ cd /test_db
$ mysql < employees.sql -p
# enter "passwd"
# This clones example
git clone https://github.com/Urigo/graphql-mesh.git
# Mount this directory into container and run.
docker run --name mesh -v `pwd`/graphql-mesh/examples/mysql-employees:/work -p 4000:4000 -d hiroyukiosaki/graphql-mesh:v0.1.17 /bin/bash -c 'sleep 3600'
# Edit .meshrc.yaml
# Point host address like this (in Mac)
# host: host.docker.internal
docker exec -it mesh /bin/bash
$ yarn install
$ yarn start
Access http://localhost:4000
Modify Dockerfile and utilize docker-compose
command to build with Dockerfile.
docker-compose build