Graphene Django integration
Project description
Graphene-Django
Graphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.
Features
- Seamless integration with Django models
- Automatic generation of GraphQL schema
- Integration with Django's authentication and permission system
- Easy querying and filtering of data
- Support for Django's pagination system
- Compatible with Django's form and validation system
- Extensive documentation and community support
Installation
To install Graphene-Django, run the following command:
pip install graphene-django
Configuration
After installation, add 'graphene_django' to your Django project's INSTALLED_APPS
list and define the GraphQL schema in your project's settings:
INSTALLED_APPS = [
# ...
'graphene_django',
]
GRAPHENE = {
'SCHEMA': 'myapp.schema.schema'
}
Usage
To use Graphene-Django, create a schema.py
file in your Django app directory and define your GraphQL types and queries:
import graphene
from graphene_django import DjangoObjectType
from .models import MyModel
class MyModelType(DjangoObjectType):
class Meta:
model = MyModel
class Query(graphene.ObjectType):
mymodels = graphene.List(MyModelType)
def resolve_mymodels(self, info, **kwargs):
return MyModel.objects.all()
schema = graphene.Schema(query=Query)
Then, expose the GraphQL API in your Django project's urls.py
file:
from django.urls import path
from graphene_django.views import GraphQLView
from . import schema
urlpatterns = [
# ...
path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
]
Testing
Graphene-Django provides support for testing GraphQL APIs using Django's test client. To create tests, create a tests.py
file in your Django app directory and write your test cases:
from django.test import TestCase
from graphene_django.utils.testing import GraphQLTestCase
from . import schema
class MyModelAPITestCase(GraphQLTestCase):
GRAPHENE_SCHEMA = schema.schema
def test_query_all_mymodels(self):
response = self.query(
'''
query {
mymodels {
id
name
}
}
'''
)
self.assertResponseNoErrors(response)
self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())
Contributing
Contributions to Graphene-Django are always welcome! To get started, check the repository's issue tracker and contribution guidelines.
License
Graphene-Django is released under the MIT License.
Resources
- Official GitHub Repository
- Graphene Documentation
- Django Documentation
- GraphQL Specification
- GraphiQL - An in-browser IDE for exploring GraphQL APIs
- Graphene-Django Community - Join the community to discuss questions and share ideas related to Graphene-Django
Tutorials and Examples
- Official Graphene-Django Tutorial
- Building a GraphQL API with Django and Graphene-Django
- Real-world example: Django, Graphene, and Relay
Related Projects
- Graphene - A library for building GraphQL APIs in Python
- Graphene-SQLAlchemy - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
- Graphene-File-Upload - A package providing an Upload scalar for handling file uploads in Graphene
- Graphene-Subscriptions - A package for adding real-time subscriptions to Graphene-based GraphQL APIs
Support
If you encounter any issues or have questions regarding Graphene-Django, feel free to submit an issue on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on 💬 Discord
Release Notes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file graphene-django-3.1.5.tar.gz
.
File metadata
- Download URL: graphene-django-3.1.5.tar.gz
- Upload date:
- Size: 84.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe42f820b9731d94bebff6d73088d0dc2ffb8c8863a6d7bf3d378412d866a3b |
|
MD5 | 37fbec4b7854fc3509b1c4953df2a468 |
|
BLAKE2b-256 | 23701b1d29d817eadc88cbbee2a049e5a1f6924f96cddbeec6c303660a3005b4 |
Provenance
File details
Details for the file graphene_django-3.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: graphene_django-3.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 110.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e42742fae21fa50e514f3acae26a9bc6cb5e51c179a97b3db5390ff258ca816 |
|
MD5 | b5532d2fe5b188b092bee9383e937017 |
|
BLAKE2b-256 | 774e5f3306f1664a4c3d77f21545914c866a66c419fdba1f43a62930a2ae57e7 |