A boilerplate for creating GraphQL server with Go
This repository contains a boilerplate code for creating GraphQL server with golang
$ git clone https://github.com/shufo/go-graphql-boilerplate
$ cd go-graphql-boilerplate
$ make up
Wait for containers running up
Name | Category | Description |
---|---|---|
gqlgen | GraphQL | Generate graphql boilercode. To configure schemas, please edit gqlgen.yml and schemas in schemas directory. |
chi | Router | A http router. route settings: server/router.go
|
sqlboiler | ORM | Generates model files from database. |
casbin | Authorization | RBAC based authorization. |
jwt-auth | JWT | A authentication middleware used by chi. |
dataloaden | N+1 query | Reduce queries on N+1 query situation. |
testify | Testing | Testing framework |
realize | Task runner | Build files by watching project files |
sql-migrate | Migration | Database migration by sql files. |
go-i18n | i18n | Internationalization |
ozzo-validation | Validation | Validates user inputs |
Go Modules | Dependency Management | Manage dependencies by go.mod |
CREATE TABLE
, ALTER TABLE
) to migrations
directory.$ make models
)schemas
directory)$ make gqlgen
)$ make test
)Add migration files to migrations
directory.
-- +migrate Up
CREATE TABLE ~~
-- +migrate Down
DROP TABLE ~
~~
Edit schema/query.graphql
todo(id: Int): Todo!
Wait until graph/generated/generated.go
generated.
Then add GraphQL resolvers.
Edit schema/mutation.graphql
createTodo(input: CreateTodoInput!): Todo!
Wait until graph/generated/generated.go
generated.
Run go get command on Local machine.
go get github.com/stretchr/testify
If you get a permission error on go.mod editing, set write permission to go.mod and go.sum file.
sudo chmod +w go.mod go.sum
$ make test