Skip to content

codeanddraw/react-django-graphQL-postgres

Repository files navigation

react-django-graphQL-postgres

GraphQL API in Django

  • Nisha Chaube

Setting up using Docker

Note: Below step may take some time

docker-compose up

docker ps

docker exec -it ####### /bin/bash

python manage.py makemigrations

python manage.py migrate

python manage.py loaddata ./Fixtures/initial_data.json

Django server url: http://127.0.0.1:8000/graphql/ React frontend url: http://localhost:3000/

Setting up Python environment

To get this project up and running you should start by having Python installed on your computer. It's advised you create a virtual environment to store your projects dependencies separately. You can install virtualenv with

pip install virtualenv

Clone or download this repository and open it in your editor of choice. In a terminal (mac/linux) or windows terminal, run the following command in the base directory of this project

python -m venv venv

That will create a new folder venv in your project directory. Next activate it with this command on mac/linux:

source venv/bin/activate

Then install the project dependencies with

pip install -r requirements.txt

Now you can run the project with this command

python manage.py runserver

Setting up postgresql database

Install Postgresql Linux

sudo apt-get install libpq-dev python-dev
sudo apt-get install postgresql postgresql-contrib

Install Postgresql Windows

Tutorial PostgreSQL windows

Setup Database and User in PostgreSQL

Based on these settings in settings.py

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "postgres,
        "USER": "postgres",
        "PASSWORD": "postgres",
        "HOST": "db"
    }
}
grant all privileges on database postgres to postgres