- A dead-simple GraphQL gateway for all your federated Go GraphQL server needs.
If you're just looking for a quick and dirty implementation of a federated gateway, paste this code into your main.go file, package and ship.
package main
import (
"fmt"
"net/http"
"github.com/nautilus/gateway"
"github.com/nautilus/graphql"
)
func main() {
// change this to point to your GraphQL servers
schemas, err := graphql.IntrospectRemoteSchemas(
"http://localhost:4000/graphql",
"http://localhost:4001/graphql",
"http://as.many.urls.as.you.want:6969/graphql"
)
if err != nil {
panic(err)
}
// create the gateway instance
gw, err := gateway.New(schemas)
if err != nil {
panic(err)
}
// your GraphQL endpoint is http(s)://host(:port)/graphql <- executes queries on POST
// navigating to this url on the browser will show the GraphQL playground UI
http.HandleFunc("/graphql", gw.PlaygroundHandler)
// start the server
fmt.Println("Starting server")
err = http.ListenAndServe(":8082", nil)
if err != nil {
fmt.Println(err.Error())
}
}-
Create a new
.envfile based on.env.examplefileGRAPHQL_ENDPOINTSvariable should be in the format"http://yourendpoint1","http://youendpoint2",...USE_FILE_CONFIGvariable should be set totrueif you want to set/use your configs insideconfig/config.yamlfile (useful for K8s-like deployments).
-
Your app will be running on port
8082and your endpoint will beapi/graphqlandapi/playgroundfor the playground -
Build the binary
make buildormake build-macfor Mac OS
Alternatively you can build a Docker image with the Dockerfile provided
- Health check endpoint
/ruok