go-graphql-gendhis

command module
v0.0.0-...-3871cc9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 6 Imported by: 0

README

CircleCI codecov Go Report Card

GO-GRAPHQL-GENDHIS

Practicing GraphQL Using Golang (Gin Gonic Framework) as Programming Language, PostgreSQL as Database

Directory structure

Your project directory structure should look like this

  + your_gopath/
  |
  +--+ src/github.com/moemoe89
  |  |
  |  +--+ go-graphql-gendhis/
  |     |
  |     +--+ main.go
  |        + api/
  |        + routers/
  |        + ... any other source code
  |
  +--+ bin/
  |  |
  |  +-- ... executable file
  |
  +--+ pkg/
     |
     +-- ... all dependency_library required

Setup and Build

$ mkdir -p src/github.com/moemoe89
$ cd src/github.com/moemoe89
$ git clone <url>
$ mv <cloned directory> go-graphql-gendhis

Running Migration

  • Copy config-sample.json to config.json and changes the value based on your configurations.
  • Create PostgreSQL database for example named simple_api and do migration with Goose https://bitbucket.org/liamstask/goose/
  • Change database configuration on dbconf.yml like dialect and dsn for each environtment
  • Do the following command
$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ goose -env=development up

Documetation with Swagger

For open swagger access via browser

{{url}}/swagger/index.html

For updating swagger

$ swag init

Running Application with Makefile

Make config file for local :

$ cp config-sample.json config-local.json

Build

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make build

Run

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make run

Stop

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make stop

Make config file for docker :

$ cp config-sample.json config-docker.json

Docker Build

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make docker-build

Docker Up

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make docker-up

Docker Down

$ cd $GOPATH/src/github.com/moemoe89/go-graphql-gendhis
$ make docker-down

How to Run with Docker

Make config file for docker :

$ cp config-sample.json config.json

Build

$ docker-compose build

Run

$ docker-compose up

Stop

$ docker-compose down

How to Run Unit Test

Run

$ go test ./...

Run with cover

$ go test ./... -cover

Run with HTML output

$ go test ./... -coverprofile=c.out && go tool cover -html=c.out

Example Request

Navigate your browser to this url for running the GraphQL console

/api/v1/graphql/user
Create
POST /api/v1/graphql/user
Content-Type: application/json
{
	"query": "mutation{Create(name:\"momo\",phone:\"0856\",email:\"m@m.com\",address:\"Indonesia\"){id,name,phone,email,address}}"
}
List
POST /api/v1/graphql/user
Content-Type: application/json
{
	"query": "{List(per_page:\"10\",page:\"1\",order_by:\"\",name:\"\",phone:\"\",email:\"\",created_at_start:\"\",created_at_end:\"\",select_field:\"\"){list{id,name,phone,email,address}}}"
}
Detail
POST /api/v1/graphql/user
Content-Type: application/json
{
	"query": "{Detail(id:\"bph2mlript32plmed820\"){id,name,phone,email,address}}"
}
Update
POST /api/v1/graphql/user
Content-Type: application/json
{
	"query": "mutation{Update(id:\"bpielbbipt341rif5i20\",name:\"momo update\",phone:\"0856\",email:\"m@m.com\",address:\"Indonesia\"){id,name,phone,email,address}}"
}
Delete
POST /api/v1/graphql/user
Content-Type: application/json
{
	"query": "mutation{Delete(id:\"bpielbbipt341rif5i20\")}"
}

Reference

Thanks to this medium link for sharing the great article

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL