Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 968 Bytes

File metadata and controls

49 lines (32 loc) · 968 Bytes

Django-GraphQL

Adds GraphQL support to your Django project.

Installation

Install the integration with:

pip install graphql-server[django]

Usage

Use the GraphQLView from graphql_server.django.

from django.urls import path
from graphql_server.django import GraphQLView

from schema import schema

urlpatterns = [
    path("graphql/", GraphQLView.as_view(schema=schema, graphiql=True)),
]

CORS

Enable CORS with django-cors-headers.

Supported options for GraphQLView

  • schema
  • graphiql
  • graphql_ide
  • allow_queries_via_get
  • multipart_uploads_enabled

You can also subclass GraphQLView and overwrite get_root_value(self, request) to have a dynamic root value per request.

class UserRootValue(GraphQLView):
    def get_root_value(self, request):
        return request.user

Contributing

See CONTRIBUTING.md