Sign inSign up

eaceto/regraphql

By eaceto

Updated over 4 years ago

A simple (yet effective) REST / HTTP to GraphQL router

Image
0

1.1K

eaceto/regraphql repository overview

ReGraphQL

GitHub go.mod Go version

Docker Image Version (latest semver) Docker Image Size (latest semver)

GitHub Workflow Status

A simple (yet effective) REST / HTTP to GraphQL router

ReGraphQL helps you expose REST/HTTP endpoints and route it to a GraphQL endpoints. Doing this has the following benefits:

  • Queries are stored and controlled server side.
  • Can modify and optimise your queries on demand without redoploying your (frontend) clients
  • Can use GET (HTTP Method) instead of GraphQL's POST

It helps you going...

From this

query($person: StarWarsPeople!) {
	getPerson(person: $person) {
		birthYear
		eyeColors
		films {
			title
		}
		gender
		hairColors
		height
		homeworld {
			name
		}
		mass
		name
		skinColors
		species {
			name
		}
		starships {
			name
		}
		vehicles {
			name
		}
	}
}

To

GET /persons/{person}

Index

Requirements

  • Go 1.18

Features

As per version 1.0.1

  • Maps HTTP params to GraphQL Variables
  • Forwards HTTP headers to GraphQL request
  • Reads configuration from .env file
  • Reads configuration from environment variables
  • Logs using Kubernetes' klog v2
  • Docker Image below 20MB
  • Exposes metrics using Prometheus
  • Exposes Liveness, Readiness and Startup Probes
  • Implements Hot reload for routes

Quick start

  1. Describe a route in a file using yaml, which matches your HTTP endpoint with your GraphQL endpoint and Query
routes:
    - http:
          uri: '/persons/{person}'
          method: GET
      graphql:
          endpoint: 'https://swapi.skyra.pw/'
          query: |
              query($person: StarWarsPeople!) {
                  getPerson(person: $person) {
                      birthYear
                      eyeColors
                      films {
                          title
                      }
                      gender
                      hairColors
                      height
                      homeworld {
                          name
                      }
                      mass
                      name
                      skinColors
                      species {
                          name
                      }
                      starships {
                          name
                      }
                      vehicles {
                          name
                      }
                  }
              }

File starwars.yml

  1. Copy starwars.yml into /tmp/config

  2. Run the service (using Docker Compose)

[sudo] docker-compose up
  1. Query your new HTTP endpoint!
curl 'http://127.0.0.1:8080/graphql/persons/lukeskywalker' --compressed

Docker Image

Docker image is based on Google's Distroless. The final image is around 11.2MB and packs only the necessary things to run the service.

docker pull eaceto/regraphql:1.0.1

Contributing

Before contributing to ReGraphQL, please read the instructions detailed in our contribution guide.

License

ReGraphQL is released under the MIT license. See LICENSE for details.

Author

Created by Ezequiel (Kimi) Aceto.

Tag summary

Content type

Image

Digest

Size

7.8 MB

Last updated

over 4 years ago

docker pull eaceto/regraphql