Package: djangorestql
DjangorestQLis a python library which allows you to turn your API made withDjango REST Framework(DRF)into a GraphQL like API.
WithDjangorestQLyou will be able toSend 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 athttps://djangorestql.ohunayogege.comRequirementsPython >= 3.5Django >= 1.11Django REST Framework >= 3.5InstallingpipinstalldjangorestqlGetting StartedUsingDjangorestQLto query data is very simple, you just have to inherit theDynamicFieldsMixinclass when defining a serializer that's all.fromrest_frameworkimportserializersfromdjango.contrib.auth.modelsimportUserfromdjangorestql.mixinsimportDynamicFieldsMixinclassUserSerializer(DynamicFieldsMixin,serializers.ModelSerializer):classMeta:model=Userfields=['id','username','email']Django RESTQLhandle all requests with aqueryparameter, this parameter is the one used to pass all fields to be included/excluded in a response. For example to selectidandusernamefields from User model, send a request with aqueryparameter as shown below.GET /users/?query={id, username}[{"id":1,"username":"ohunayo"},...]Django RESTQLsupport 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 havelocationas a nested field on User model.fromrest_frameworkimportserializersfromdjango.contrib.auth.modelsimportUserfromdjango_restql.mixinsimportDynamicFieldsMixinfromapp.modelsimportGroupSerializer,LocationSerializerclassLocationSerializer(DynamicFieldsMixin,serializers.ModelSerializer):classMeta:model=Locationfields=['id','country','city','street']classUserSerializer(DynamicFieldsMixin,serializers.ModelSerializer):location=LocationSerializer(many=False,read_only=True)classMeta:model=Userfields=['id','username','email','location']If you want onlycountryandcityfields on alocationfield when retrieving users here is how you can do itGET /users/?query={id, username, location{country, city}}[{"id":1,"username":"ohunayo","location":{"contry":"Nigeria","city":"Lagos"}},...]Documentation :pencil:You can do a lot withDjangorestQLapart from just querying data, full documentation for this project is available athttps://https://djangorestql.ohunayogege.com, you are encouraged to read it inorder to utilize this library to the fullest.Running Testspython runtests.pyCreditsGraphQLUsage 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 ofdrf-dynamic-fieldslibrary 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.ContributingWe welcome all contributions. Please read ourCONTRIBUTING.mdfirst. You can submit any ideas aspull requestsor asGitHub issues. If you'd like to improve code, check out theCode Style Guideand have a good time!.