A simple example of using GraphQL to effectively retrieve data from a Postgres database.
-
Build a Docker image for a sample
store
database$ docker build -t store .
-
And then run it
$ docker run --rm -p 5432:5432 store
-
Build the project
$ go build
-
Then run the binary
$ ./graphqldb
Now you should be able to able to send GraphQL reqests to http://localhost:8080/graphql
. For example
$ cat <<EOF | curl -X POST -d @- localhost:8080/graphql | python -m json.tool
{
"query": "{
orders(first: 2) {
id,
time,
customer {
name,
},
products {
name,
quantity,
price,
},
}
}"
}
EOF