Sign inSign up

hiroyukiosaki/graphql-mesh

By hiroyukiosaki

Updated almost 5 years ago

Simple docker image to run GraphQL Mesh

Image
1

10K+

hiroyukiosaki/graphql-mesh repository overview

GraphQL Mesh Docker (supports Kubernetes/Helm)

on or /

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.

TL;DR

# Run on Docker
docker run --name mesh -p 4000:4000 -it --volume ${PWD}/docker/work/.meshrc:/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
  }
}

Architecture

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)

Docker Images for GraphQL Mesh

TagDescription
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

Run

You can choose step for your envionment (Docker or Kubernetes)

1. On Docker

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.

2. On Kubernetes

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
2.1 Use kubectl
# 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 &
2.2 Use helm
# 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>
Parameters
NameDescriptionDefault
mountConfigMap.".meshrc.yaml"ConfigMap name containing .meshrc.yaml fileNone
mountConfigMap."example-query.graphql"ConfigMap name containing example-query.graphql fileNone
mountConfigMap."init.sh"ConfigMap name containing init.sh file. If it exists, container runs GraphQL Mesh after it runs init.shNone
mount.".meshrc.yaml"inlined .meshrc.yaml fileNone
mount."example-query.graphql"inlined example-query.graphql fileNone
mount."init.sh"inlined init.sh file. If it exists, container runs GraphQL Mesh after it runs init.shNone
replicaCountCount of replica pods1
image.repositoryImage repositoryhiroyukiosaki/graphql-mesh
image.tagImage taglatest
image.pullPolicyimagePullPolicyIfNotPresent
imagePullSecretsArray of secret name[]
serviceAccount.createCreate a ServiceAccount for GraphQL Meshtrue
serviceAccount.nameServiceAccount name""
serviceAccount.annotationsAnnotation structure for ServiceAccount{}
service.typeService typeClusterIP
service.portService port80
service.annotationsAnnotation structure for Service{}
ingress.enabledEnable an Ingressfalse
ingress.annotationsAnnotation structure for Ingress{}
ingress.hosts.hostHost name for Ingressgraphql-mesh.127.0.0.1.xip.io
ingress.hosts.pathHost path array for Ingress[]
resourcesResource limits and requests (e.g. limits: { cpu: 100m, memory: 128Mi }){}

Please refer to sample parameter values file for details.

Customize

There are two ways to customize GraphQL Mesh Docker.

  • Customize .meshrc.yaml
  • Clone an existing example and run in Docker

Customize .meshrc

  • Create your .meshrc.yaml. Please follow the guidance of the official document above.

  • Place .meshrc.yaml in the current directory.

    On Docker
    • 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
    On Kubernetes (not using Helm)
    • 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
    With Helm

    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
    

Clone another existing example and run in Docker

# 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'

Example

GraphQL Mesh with MySQL

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

Build on your own

Modify Dockerfile and utilize docker-compose command to build with Dockerfile.

docker-compose build

Tag summary

Content type

Image

Digest

Size

414.3 MB

Last updated

almost 5 years ago

docker pull hiroyukiosaki/graphql-mesh