MCPcopy Index your code
hub / github.com/graphql-python/graphene-django

github.com/graphql-python/graphene-django @v3.2.3

repository ↗ · DeepWiki ↗ · release v3.2.3 ↗ · + Follow
1,278 symbols 3,842 edges 164 files 83 documented · 6% 2 cross-repo links
README

Graphene Logo Graphene-Django

build pypi Anaconda-Server Badge coveralls

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

Tutorials and Examples

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

Core symbols most depended-on inside this repo

execute
called by 177
graphene_django/debug/sql/tracking.py
filter
called by 20
graphene_django/filter/filters/list_filter.py
get_django_field_description
called by 17
graphene_django/converter.py
camelize
called by 12
graphene_django/utils/utils.py
mutate_and_get_payload
called by 12
graphene_django/rest_framework/mutation.py
convert_django_field
called by 11
graphene_django/converter.py
get_form_field_description
called by 11
graphene_django/forms/converter.py
initialize
called by 8
examples/starwars/data.py

Shape

Function 509
Class 455
Method 279
Route 35

Languages

Python99%
TypeScript1%

Modules by API surface

graphene_django/tests/test_query.py98 symbols
graphene_django/filter/tests/test_fields.py85 symbols
graphene_django/tests/test_converter.py70 symbols
graphene_django/tests/test_views.py69 symbols
graphene_django/tests/test_types.py59 symbols
graphene_django/rest_framework/tests/test_mutation.py48 symbols
graphene_django/forms/tests/test_djangoinputobject.py43 symbols
graphene_django/converter.py40 symbols
graphene_django/rest_framework/tests/test_field_converter.py38 symbols
graphene_django/tests/test_get_queryset.py37 symbols
graphene_django/tests/test_fields.py34 symbols
graphene_django/rest_framework/serializer_converter.py34 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

Sphinx7.0.0 · 1×
django3.2 · 1×
graphene2.1 · 1×
graphene-django3.1 · 1×
graphql-core2.1 · 1×
pygments-graphql-lexer0.1.0 · 1×
sphinx-autobuild2021.3.14 · 1×

For agents

$ claude mcp add graphene-django \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact