Skip to content

A Typescript GraphQL API Boilerplate with GraphQL-Yoga, typeORM, JWT

Notifications You must be signed in to change notification settings

mununki/ts-graphql-api-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typescript GraphQL API Boilerplate

This is a GraphQL API boilerplate built with Typescript, graphQL-yoga, typeORM, JWT

Stacks

Features

  • User Sign Up & Sign In
  • Change a Password, Profile

How to Run

Configuration

  1. Create a database
postgres=# CREATE DATABASE any;
  1. Create a user as owner of database
postgres=# CREATE USER any WITH ENCRYPTED PASSWORD 'any';

postgres=# ALTER DATABASE any OWNER TO any;
  1. Grant all privileges to user for the database
postgres=# GRANT ALL PRIVILEGES ON DATABASE any TO any;
  1. Configure .env
JWT_SECRET_KEY=jwt-secret
DB_NAME=any
DB_ENDPOINT=localhost
DB_USERNAME=any
DB_PASSWORD=any

Set a JWT secret key

Run the server

  • Dev
$ yarn dev
  • Prod
$yarn build
$yarn start

GraphQL Playground

Connect to http://localhost:4000

Authentication : JWT

You need to set the Http request headers X-JWT: {JWT_token}

Usage

Sign Up

mutation {
  SignUp(email: "test@test.com", password: "12345678", fullName: "graphql", nickName: "ts") {
    ok
    error
    user {
      id
      email
      fullName
      nickName
      bio
      avatar
      createdAt
      updatedAt
    }
    token
  }
}

Sign In

mutation {
  SignIn(email: "test@test.com", password: "12345678") {
    ok
    error
    token
  }
}

Change a Password

mutation {
  ChangePassword(password: "87654321") {
    ok
    error
    user {
      id
      email
      fullName
      nickName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Change a Profile

mutation {
  ChangeProfile(bio: "developer", avatar: "developer.png") {
    ok
    error
    profile {
      id
      email
      fullName
      nickName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Get my profile

query {
  getMyProfile {
    ok
    error
    profile {
      id
      email
      fullName
      nickName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Reference

About

A Typescript GraphQL API Boilerplate with GraphQL-Yoga, typeORM, JWT

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published