Code Monkey home page Code Monkey logo

antcolonyquantitative_api's Introduction

Tougu Server

Environment setup

  1. We use yarn to manage the packages, so make sure you have yarn installed. You can run npm install -g yarn to install yarn.
    We use PostgreSQL as our local database, you can refer this To run a PostgreSQL database locally: to setup your local database
  2. clone this repo.
  3. run yarn in the project root.
  4. add a .env file, and include the following
DATABASE_URL=postgresql://postgres:TOUGU_ADMIN@localhost:5432/toguDb
JWT_SECRET=hello_tougu
  1. Reset your local database, using
npx prisma migrate reset

Navigate to prisma folder, and init prisma

cd prisma/touguDb
npx prisma generate
  1. run yarn start to start developing.

Use mutation to create your first user:

  1. Make sure the project is running at: http://localhost:4000/graphql
  2. Create your first user using the following mutation:
mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    token
  }
}
{
  "input": {
    "email": "[email protected]",
    "password":"tougu_admin",
    "displayName": "admin",
    "mobile": "0412 345 678",
    "realName": "tougu_master",
    "ref": "admin"
  }
}

Authenticate user and get your user token before running queries

Running the following query to get a token

query AuthenticUser($email: String!, $password: String!) {
  authenticUser(email: $email, password: $password) {
    token
  }
}

{
"email": "[email protected]",
"password": "tougu_admin"
}

Running your queries and mutations with a token

Running an example query like:

query GetUsers {
  getUsers {
    id
    email
  }
}

And put your token in Headers as:

Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY5NzMyMzgwOCwiZXhwIjoxNjk3MzY3MDA4fQ.Xo4xASTWtz_I3-jAv5l-DGk9LDCy6RxkwMCmKtCGEd4

To run a PostgreSQL database locally:

  1. Install docker locally:https://www.docker.com/get-started

  2. Pull the PostgreSQL Image:

    docker pull postgres
    
  3. Run a PostgreSQL Container:

    docker run --name togudb -e POSTGRES_PASSWORD=TOUGU_ADMIN -e POSTGRES_DB=toguDb -p 5432:5432 -d postgres
    
  4. Wait for the Container to Start and check the container's status:

    docker ps
    
  5. Download a DBeaver: https://dbeaver.io/download/, connect your db using DBeaver by using the following config:

    Host: localhost
    Port: 5432
    Database: toguDb
    Username: postgres
    Password: TOUGU_ADMIN
    

6 (optional). Stop and remove the container: (you need to run step 3 again once you remove it):

docker stop togudb
docker rm togudb

antcolonyquantitative_api's People

Contributors

chris-wang avatar ucfyao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.