Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Graphene Django integration

Project Description

Please read UPGRADE-v1.0.md to learn how to upgrade to Graphene 1.0.


Graphene-Django

A Django integration for Graphene.

Installation

For instaling graphene, just run this command in your shell

pip install "graphene-django>=1.0"

Settings

INSTALLED_APPS = (
    # ...
    'graphene_django',
)

GRAPHENE = {
    'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
}

Urls

We need to set up a GraphQL endpoint in our Django app, so we can serve the queries.

from django.conf.urls import url
from graphene_django.views import GraphQLView

urlpatterns = [
    # ...
    url(r'^graphql', GraphQLView.as_view(graphiql=True)),
]

Examples

Here is a simple Django model:

from django.db import models

class UserModel(models.Model):
    name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

To create a GraphQL schema for it you simply have to write the following:

from graphene_django import DjangoObjectType
import graphene

class User(DjangoObjectType):
    class Meta:
        model = UserModel

class Query(graphene.ObjectType):
    users = graphene.List(User)

    @graphene.resolve_only_args
    def resolve_users(self):
        return UserModel.objects.all()

schema = graphene.Schema(query=Query)

Then you can simply query the schema:

query = '''
    query {
      users {
        name,
        lastName
      }
    }
'''
result = schema.execute(query)

To learn more check out the following examples:

Contributing

After cloning this repo, ensure dependencies are installed by running:

pip install -e ".[test]"

After developing, the full test suite can be evaluated by running:

py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode

Documentation

The documentation is generated using the excellent Sphinx and a custom theme.

The documentation dependencies are installed by running:

cd docs
pip install -r requirements.txt

Then to produce a HTML version of the documentation:

make html
Release History

Release History

History Node

2.0.dev2017073101

History Node

2.0.dev2017072601

History Node

2.0.dev2017072501

This version
History Node

1.3

History Node

1.2.1

History Node

1.2.0

History Node

1.1.0

History Node

1.0

History Node

1.0.dev20160922000001

History Node

1.0.dev20160920000001

History Node

1.0.dev20160919000004

History Node

1.0.dev20160919000003

History Node

1.0.dev20160919000002

History Node

1.0.dev20160919000001

History Node

1.0.dev20160917000001

History Node

1.0.dev20160910000001

History Node

1.0.dev20160909000001

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
graphene-django-1.3.tar.gz (31.6 kB) Copy SHA256 Checksum SHA256 Source Apr 20, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting