go-graphql-api-boilerplate

command module
v0.0.0-...-c193d7f Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 12 Imported by: 0

README

Go GraphQL API Boilerplate

Stacks

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

// 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
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
$ 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
mutation {
  signInGoogle(idToken: "12345678") {
    ok
    error
    token
  }
}
mutation {
  signInKakao(code: "12345678") {
    ok
    error
    token
  }
}
Change a Profile
mutation {
  changeProfile(nickname: "Go developer") {
    ok
    error
    user {
      id
      email
      nickname
      createdAt
      updatedAt
    }
  }
}
Get my profile
query {
  getMyProfile {
    ok
    error
    user {
      id
      email
      nickname
      createdAt
      updatedAt
    }
  }
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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