An example Golang server that uses GraphQL and Relay that serves up Star Wars data.
Taken from: Playground
- graphql-go: Golang GraphQL library
- graphql-hander: Golang HTTP.Handler for graphl-go
- Object88's Relay
-
Make sure you have go installed.
-
Make sure you have
GOPATH
set to the directory where this project is installed:
$ export GOPATH=`pwd`
- Run the app:
$ go run main.go
Fetch the Rebel faction name:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { rebels { name } }",
"variables": null
}'
Fetch the first Rebel ship:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { rebels { name ships(first: 1) { edges { node { name } } } } }",
"variables": null
}'
Fetch all Rebel ships:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { rebels { name ships { edges { node { name } } } } }",
"variables": null
}'
Fetch the Empire faction name:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { empire { name } }",
"variables": null
}'
Fetch the first Empire ship:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { empire { name ships(first: 1) { edges { node { name } } } } }",
"variables": null
}'
Fetch all Empire ships:
$ curl -X POST http://localhost:3000/graphql -H 'Content-Type: application/json' -d '
{
"query": "query { empire { name ships { edges { node { name } } } } }",
"variables": null
}'
How to do stuff with Docker.
$ docker build -t star_wars_go .
$ docker run --publish 3000:3000 --name star_wars_go --rm star_wars_go
$ docker stop star_wars_go