Categorygithub.com/eaceto/ReGraphQL
modulepackage
1.0.2
Repository: https://github.com/eaceto/regraphql.git
Documentation: pkg.go.dev

# README

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

  • 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

Service Endpoints

Liveness

GET /health/liveness

{"hostname":"pod_67804","status":"up"}

Returns HTTP Status Code OK (200) with the following JSON as soon as the application starts

{"hostname":"<< hostname >>","status":"up"}

Readiness

GET /health/readiness

{"hostname":"pod_67804","status":"ready"}
  1. If the application is Ready to receive requests

Returns HTTP Status Code OK (200) with the following JSON:

{"hostname":"<< hostname >>","status":"ready"}
  1. If the application is Not Ready to receive requests

Returns HTTP Status Code Precondition Failed (412) with the following JSON:

{"hostname":"<< hostname >>","status":"waiting"}

Metrics

The service exposes a Prometheus metrics endpoint at /metrics

GET /metrics

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0

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:latest

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.

# Packages

* ReGraphQL - Proxy * This is the proxy service of project ReGraphQL * * Contact: [email protected] */ Package app is in charge of loading application Configuration, and providing (app) global constants.
Package helpers has a set of functions that makes the some task easier.
No description provided by the author
No description provided by the author