Skip to main content

No project description provided

Project description

DjangorestQL is a python library which allows you to turn your API made with Django REST Framework(DRF) into a GraphQL like API. With DjangorestQL you will be able to

  • Send a query to your API and get exactly what you need, nothing more and nothing less.

  • Control the data you get, not the server.

  • Get predictable results, since you control what you get from the server.

  • Get nested resources in a single request.

  • Avoid Over-fetching and Under-fetching of data.

  • Write(create & update) nested data of any level with flexibility.

am sure you will enjoy it. Isn't it cool?

Want to see how this library is making all that possible?

Check out the full documentation at https://djangorestql.ohunayogege.com

Requirements

  • Python >= 3.5
  • Django >= 1.11
  • Django REST Framework >= 3.5

Installing

pip install djangorestql

Getting Started

Using DjangorestQL to query data is very simple, you just have to inherit the DynamicFieldsMixin class when defining a serializer that's all.

from rest_framework import serializers
from django.contrib.auth.models import User
from djangorestql.mixins import DynamicFieldsMixin


class UserSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'email']

Django RESTQL handle all requests with a query parameter, this parameter is the one used to pass all fields to be included/excluded in a response. For example to select id and username fields from User model, send a request with a query parameter as shown below.

GET /users/?query={id, username}

[
    {
        "id": 1,
        "username": "ohunayo"
    },
    ...
]

Django RESTQL support querying both flat and nested resources, so you can expand or query nested fields at any level as defined on a serializer. In an example below we have location as a nested field on User model.

from rest_framework import serializers
from django.contrib.auth.models import User
from django_restql.mixins import DynamicFieldsMixin

from app.models import GroupSerializer, LocationSerializer


class LocationSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
    class Meta:
        model = Location
        fields = ['id', 'country',  'city', 'street']


class UserSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
    location = LocationSerializer(many=False, read_only=True) 
    class Meta:
        model = User
        fields = ['id', 'username', 'email', 'location']

If you want only country and city fields on a location field when retrieving users here is how you can do it

GET /users/?query={id, username, location{country, city}}

[
    {
        "id": 1,
        "username": "ohunayo",
        "location": {
            "contry": "Nigeria",
            "city": "Lagos"
        }
    },
    ...
]

Documentation :pencil:

You can do a lot with DjangorestQL apart from just querying data, full documentation for this project is available at https://https://djangorestql.ohunayogege.com, you are encouraged to read it inorder to utilize this library to the fullest.

Running Tests

python runtests.py

Credits

  • GraphQL Usage was an idea introduced to me by a friend of mine on JavaScript, so i decided to use it on Django.
  • My intention is to extend the capability of drf-dynamic-fields library to support more functionalities like allowing to query nested fields both flat and iterable at any level and allow writing on nested fields while maintaining simplicity and to also relief developer stress.

Contributing PRs Welcome

We welcome all contributions. Please read our CONTRIBUTING.md first. You can submit any ideas as pull requests or as GitHub issues. If you'd like to improve code, check out the Code Style Guide and have a good time!.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangorestql-1.0.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangorestql-1.0.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file djangorestql-1.0.1.tar.gz.

File metadata

  • Download URL: djangorestql-1.0.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for djangorestql-1.0.1.tar.gz
Algorithm Hash digest
SHA256 af28f86058b0430d5318db004b8c1bb9def6786972a4bfc82f657d788b78e6be
MD5 ba6b62cb07cb4089f445769e4ec056ca
BLAKE2b-256 ab2641a0ea1fa63adfc80c053daaac017f2743f9699fc5488d253cc90c3c5e92

See more details on using hashes here.

File details

Details for the file djangorestql-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: djangorestql-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for djangorestql-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1dcc67ad447d1417b2279c6177e96634888cb7ac3fd48071656188c173fe5a2
MD5 81d5e4f001cb7f493ae4f8f5c7ff1e5e
BLAKE2b-256 ea22710121dde0d287c34169eca0e6cb208c52dd9c7fe5b38a0820f356ec719a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page