A GraphQL API tutorial implemented using Go
$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
$ go install gotest.tools/gotestsum@latest
$ go get .
$ docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=dbpass -e MYSQL_DATABASE=go_graphql_tutorial -d mysql:latest
$ docker logs -f mysql # Please wait for the MySQL database to start...
$ $(go env GOPATH)/bin/migrate -database mysql://root:dbpass@localhost:3306/go_graphql_tutorial -path internal/pkg/db/migrations/mysql up
$ go run server.go
One may then please visit the GraphiQL web browser interface for querying and submitting mutations to the server API.
One example query would be:
query {
todos {
id
text,
done,
user {
id,
name
}
}
}
One example mutation would be:
mutation CreateTodo($input: NewTodo!) {
createTodo(input: $input) {
id,
text,
user {
id,
name
}
}
}
...with the variables being the following:
{
"input": {
"text": "new todo",
"userId": "user-id"
}
}
$ cd client/
$ yarn install
$ cd client/
$ yarn run dev
One may then please visit the JavaScript web client.
$ $(go env GOPATH)/bin/golangci-lint run
$ $(go env GOPATH)/bin/gotestsum
$ yarn lint
$ yarn test