This a template for an GraphQL API in Golang with
- Gin Server: Fast server
- Graphql-Go (Gophers): GraphQL Engine
- Gorm: ORM in GO (connected with postgreSQL)
- GraphiQL: GraphQL web client
- SQL-Migrate: DB migrations
- Dep: Go dependecy manager
You can install asdf
if you are in linux or MacOS, this allow you to have several dev envs including GOLANG
Add in your ~/.bashrc
or ~/.zshrc
export GOPATH=$HOME/go
export PATH="$PATH:$GOPATH/bin"
This project should be at $GOPATH/src
it means ~/go/src
And the name should be test_articles
, please rename it!
So the final code should be at ~/go/src/test_articles
Now, you have to install some commands (2. ,3. ,4.)
go get github.com/codegangsta/gin
go get -v github.com/rubenv/sql-migrate/...
go get -u github.com/golang/dep/cmd/dep
cp .env-example .env
And change your configuration values
dep ensure
export `egrep -v "#" .env | xargs -0`
sql-migrate up -config="config/sql-migrate.yml"
go run db/seeds/adding_articles.go
gin
The API should be at http://localhost:3000/graphql
Run this at least once in your console
export `egrep -v "#" .env | xargs -0`
Creating a migration
sql-migrate new -config="config/sql-migrate.yml" <name>
Migrating
sql-migrate up -config="config/sql-migrate.yml"
Rollback
sql-migrate down -config="config/sql-migrate.yml"