/Django-graphql-boilerplate

Django and graphql api

Primary LanguagePythonMIT LicenseMIT

Docker-django-development-env

Docker Compose to set up and run a Django/PostgreSQL app

Only for the first time

To create Django project

$ docker-compose run web django-admin startproject project_name .

If in linux: Change the ownership of the new files in the host

$ sudo chown -R $USER:$USER .
 $ docker-compose run web chmod -R 777 .

Replace the DATABASES = ... with the following:

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.postgresql',
       'NAME': 'postgres',
       'USER': 'postgres',
       'HOST': 'db',
       'PORT': 5432,
   }
}

Start coding

 $ docker-compose up

Enter the docker container to create env

$ docker exec -it <container-name> /bin/bash

Inside the container To install an venv and active it

 $ virtualenv venv -p python
 $ source venv/bin/activate
 $ pip install -r requirements.txt
 $ python manage.py migrate
 $ python manage.py createsuperuser

To shutdown

$ docker-compose down

More info

django_compose

Development

Add new app

  1. Add the app
  2. Add the model
  3. Add the app to the installed Apps
  4. Make migrations
  5. add the schema folder
  6. add the query @see: links.schemes.link.query
  7. add the mutation @see: links.schemes.link.mutation
  8. add the query and the mutation to the main schema in the root project

GraphQl APIs

after starting the server visit graphql

To test

  • to obtain the token use createUser mutation
  • with authorization use Insomnia clint or postman and set the Authorization in the Header to jwt

More info

graphql-python