Skip to content

Commit

Permalink
Merge a664faa into 0d178b3
Browse files Browse the repository at this point in the history
  • Loading branch information
phalt committed May 6, 2019
2 parents 0d178b3 + a664faa commit c856a3b
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 172 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -7,7 +7,11 @@ Please read [UPGRADE-v2.0.md](https://github.com/graphql-python/graphene/blob/ma

A [Django](https://www.djangoproject.com/) integration for [Graphene](http://graphene-python.org/).

## Installation
## Documentation

[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)

## Quickstart

For installing graphene, just run this command in your shell

Expand Down Expand Up @@ -39,7 +43,7 @@ from graphene_django.views import GraphQLView

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

Expand Down
12 changes: 9 additions & 3 deletions README.rst
Expand Up @@ -10,8 +10,14 @@ to learn how to upgrade to Graphene ``2.0``.
A `Django <https://www.djangoproject.com/>`__ integration for
`Graphene <http://graphene-python.org/>`__.

Installation
------------

Documentation
-------------

`Visit the documentation to get started! <https://docs.graphene-python.org/projects/django/en/latest/>`__

Quickstart
----------

For installing graphene, just run this command in your shell

Expand Down Expand Up @@ -46,7 +52,7 @@ serve the queries.
urlpatterns = [
# ...
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
]
Examples
Expand Down
6 changes: 3 additions & 3 deletions docs/authorization.rst
Expand Up @@ -155,7 +155,7 @@ To restrict users from accessing the GraphQL API page the standard Django LoginR

.. code:: python
#views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from graphene_django.views import GraphQLView
Expand All @@ -171,9 +171,9 @@ For Django 1.9 and below:
urlpatterns = [
# some other urls
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
url(r'^graphql$', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
]
For Django 2.0 and above:

.. code:: python
Expand Down
48 changes: 47 additions & 1 deletion docs/filtering.rst
Expand Up @@ -136,7 +136,7 @@ pre-filter animals owned by the authenticated user (set in ``context.user``).
class AnimalFilter(django_filters.FilterSet):
# Do case-insensitive lookups on 'name'
name = django_filters.CharFilter(lookup_type='iexact')
name = django_filters.CharFilter(lookup_type=['iexact'])
class Meta:
model = Animal
Expand All @@ -146,3 +146,49 @@ pre-filter animals owned by the authenticated user (set in ``context.user``).
def qs(self):
# The query context can be found in self.request.
return super(AnimalFilter, self).qs.filter(owner=self.request.user)
Ordering
--------

You can use ``OrderFilter`` to define how you want your returned results to be ordered.

Extend the tuple of fields if you want to order by more than one field.

.. code:: python
from django_filters import FilterSet, OrderingFilter
class UserFilter(FilterSet):
class Meta:
model = UserModel
order_by = OrderingFilter(
fields=(
('created_at', 'created_at'),
)
)
class Group(DjangoObjectType):
users = DjangoFilterConnectionField(Ticket, filterset_class=UserFilter)
class Meta:
name = 'Group'
model = GroupModel
interfaces = (relay.Node,)
def resolve_users(self, info, **kwargs):
return UserFilter(kwargs).qs
with this set up, you can now order the users under group:

.. code::
query {
group(id: "xxx") {
users(orderBy: "-created_at") {
xxx
}
}
}
74 changes: 0 additions & 74 deletions docs/form-mutations.rst

This file was deleted.

23 changes: 20 additions & 3 deletions docs/index.rst
@@ -1,17 +1,34 @@
Graphene-Django
===============

Contents:
Welcome to the Graphene-Django docs.

Graphene-Django is built on top of `Graphene <https://docs.graphene-python.org/en/latest/>`__.
Graphene-Django provides some additional abstractions that make it easy to add GraphQL functionality to your Django project.

First time? We recommend you start with the installation guide to get set up and the basic tutorial.
It is worth reading the `core graphene docs <https://docs.graphene-python.org/en/latest/>`__ to familiarize yourself with the basic utilities.

Core tenants
------------

If you want to expose your data through GraphQL - read the ``Installation``, ``Schema`` and ``Queries`` section.


For more advanced use, check out the Relay tutorial.

.. toctree::
:maxdepth: 0
:maxdepth: 1

installation
tutorial-plain
tutorial-relay
schema
queries
mutations
filtering
authorization
debug
rest-framework
form-mutations
introspection
testing
69 changes: 69 additions & 0 deletions docs/installation.rst
@@ -0,0 +1,69 @@
Installation
============

Graphene-Django takes a few seconds to install and set up.

Requirements
------------

Graphene-Django currently supports the following versions of Django:

* Django 2.X

Installation
------------

.. code:: bash
pip install graphene-django
**We strongly recommend pinning against a specific version of Graphene-Django because new versions could introduce breaking changes to your project.**

Add ``graphene_django`` to the ``INSTALLED_APPS`` in the ``settings.py`` file of your Django project:

.. code:: python
INSTALLED_APPS = [
...
'django.contrib.staticfiles', # Required for GraphiQL
'graphene_django'
]
We need to add a graphql URL to the ``urls.py`` of your Django project:

.. code:: python
from django.conf.urls import url
from graphene_django.views import GraphQLView
urlpatterns = [
# ...
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
]
(Change ``graphiql=True`` to ``graphiql=False`` if you do not want to use the GraphiQL API browser.)

Finally, define the schema location for Graphene in the ``settings.py`` file of your Django project:

.. code:: python
GRAPHENE = {
'SCHEMA': 'django_root.schema.schema'
}
Where ``path.schema.schema`` is the location of the ``Schema`` object in your Django project.

The most basic ``schema.py`` looks like this:

.. code:: python
import graphene
class Query(graphene.ObjectType):
pass
schema = graphene.Schema(query=Query)
To learn how to extend the schema object for your project, read the basic tutorial.

0 comments on commit c856a3b

Please sign in to comment.