Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mununki/go-graphql-api-boilerplate
A Boilerplate of GraphQL API built in Go + graphql-go + gorm
https://github.com/mununki/go-graphql-api-boilerplate
boilerplate go gorm graphql graphql-api graphql-go starter-kit
Last synced: 2 months ago
JSON representation
A Boilerplate of GraphQL API built in Go + graphql-go + gorm
- Host: GitHub
- URL: https://github.com/mununki/go-graphql-api-boilerplate
- Owner: mununki
- License: mit
- Created: 2019-04-20T16:57:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T00:04:59.000Z (over 3 years ago)
- Last Synced: 2024-10-08T22:05:01.423Z (3 months ago)
- Topics: boilerplate, go, gorm, graphql, graphql-api, graphql-go, starter-kit
- Language: Go
- Homepage:
- Size: 77.1 KB
- Stars: 80
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go GraphQL API Boilerplate
## Stacks
- Go
- GraphQL : [graphql-go](https://github.com/graph-gophers/graphql-go)
- Querybuilder : [goqu](https://github.com/doug-martin/goqu)## Features
- User Sign Up & Sign In with OAuth (Google, Kakao)
- Change the Profile## How to Run
### Initialize DB
1. Create a database using `sql/create.sql` (MYSQL)
2. Configure the db in `db/db.go`
```go
// ConnectDB : connecting DB
func ConnectDB() (*DB, error) {
db, err := sql.Open("mysql", "api:your_password$@/database_name?parseTime=true")if err != nil {
panic(err)
}// https://github.com/go-sql-driver/mysql/#important-settings
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetConnMaxIdleTime(10)errPing := db.Ping()
if errPing != nil {
panic(err.Error())
}qb := goqu.New("mysql", db)
return &DB{qb}, nil
}
```### Make `.env` file
```env
STAGE=PROD // PROD for production or else for debug
JWT_SECRET=my_secret
GOOGLE_CLIENT_ID=your_google_web_client_id
KAKAO_REST_API_KEY=your_kakao_rest_api_key
KAKAO_REDIRECT_URI=http://localhost:8280/oauth/kakao/redirect
```### Run the server
```shell
$ go run server.go
```### GraphQL Playground
Connect to http://localhost:8080
### Authentication : JWT
You need to set the Http request headers `Authorization`: `Bearer {JWT_token}`
## Usage
### Sign In
```graphql
mutation {
signInGoogle(idToken: "12345678") {
ok
error
token
}
}
``````graphql
mutation {
signInKakao(code: "12345678") {
ok
error
token
}
}
```### Change a Profile
```graphql
mutation {
changeProfile(nickname: "Go developer") {
ok
error
user {
id
nickname
createdAt
updatedAt
}
}
}
```### Get my profile
```graphql
query {
getMyProfile {
ok
error
user {
id
nickname
createdAt
updatedAt
}
}
}
```