Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphql-python/graphene-django
Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
https://github.com/graphql-python/graphene-django
django graphene graphql python
Last synced: 5 days ago
JSON representation
Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
- Host: GitHub
- URL: https://github.com/graphql-python/graphene-django
- Owner: graphql-python
- License: mit
- Created: 2016-09-17T23:26:25.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T01:50:19.000Z (2 months ago)
- Last Synced: 2024-10-29T10:52:08.151Z (about 2 months ago)
- Topics: django, graphene, graphql, python
- Language: Python
- Homepage: http://docs.graphene-python.org/projects/django/en/latest/
- Size: 1.3 MB
- Stars: 4,302
- Watchers: 70
- Forks: 768
- Open Issues: 159
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-graphql - graphene-django - A Django integration for Graphene. (Libraries / Python Libraries)
- -awesome-django - graphene-django - GraphQL for Django. (Third-Party Packages / APIs)
- awesome-starts - graphql-python/graphene-django - Integrate GraphQL into your Django project. (Python)
- awesome-django - graphene-django - GraphQL for Django. (Third-Party Packages / APIs)
- awesome-graphql - graphene-django - A Django integration for Graphene. (Libraries / Python Libraries)
- best-of-web-python - GitHub - 18% open ยท โฑ๏ธ 18.04.2024): (GraphQL Utilities)
- best-django-resource - graphene-django - Django integration for building GraphQL APIs. (API)
- stars - graphql-python/graphene-django - Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration. (Python)
- stars - graphql-python/graphene-django - Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration. (Python)
README
# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django
[![build][build-image]][build-url]
[![pypi][pypi-image]][pypi-url]
[![Anaconda-Server Badge][conda-image]][conda-url]
[![coveralls][coveralls-image]][coveralls-url][build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg
[build-url]: https://github.com/graphql-python/graphene-django/actions
[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat
[pypi-url]: https://pypi.org/project/graphene-django/
[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master
[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
[conda-url]: https://anaconda.org/conda-forge/graphene-djangoGraphene-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:
```sh
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:
```python
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:
```python
import graphene
from graphene_django import DjangoObjectType
from .models import MyModelclass MyModelType(DjangoObjectType):
class Meta:
model = MyModelclass 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:
```python
from django.urls import path
from graphene_django.views import GraphQLView
from . import schemaurlpatterns = [
# ...
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:
```python
from django.test import TestCase
from graphene_django.utils.testing import GraphQLTestCase
from . import schemaclass MyModelAPITestCase(GraphQLTestCase):
GRAPHENE_SCHEMA = schema.schemadef 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](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/main/CONTRIBUTING.md).
## License
Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/main/LICENSE).
## Resources
* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)
* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)
* [Django Documentation](https://docs.djangoproject.com/en/stable/)
* [GraphQL Specification](https://spec.graphql.org/)
* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs
* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django## Tutorials and Examples
* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)
* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)
* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)## Related Projects
* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python
* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene
* [Graphene-Subscriptions](https://github.com/graphql-python/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](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [๐ฌ Discord](https://discord.gg/Fftt273T79)
## Release Notes
* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)