Skip to content

Commit 57dbcd3

Browse files
committed
Merge remote-tracking branch 'remote/master' into recursive-nodes
2 parents e82ee88 + fd91f78 commit 57dbcd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1335
-53
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,16 @@ target/
6565
# Databases
6666
*.sqlite3
6767
.vscode
68+
69+
# swap
70+
[._]*.s[a-v][a-z]
71+
[._]*.sw[a-p]
72+
[._]s[a-v][a-z]
73+
[._]sw[a-p]
74+
# session
75+
Session.vim
76+
# temporary
77+
.netrwhist
78+
*~
79+
# auto-generated tag files
80+
tags

docs/authorization.rst

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Authorization in Django
22
=======================
33

4-
There are two main ways you may want to limit access to data when
4+
There are several ways you may want to limit access to data when
55
working with Graphene and Django: limiting which fields are accessible
66
via GraphQL and limiting which objects a user can access.
77

@@ -34,6 +34,20 @@ This is easy, simply use the ``only_fields`` meta attribute.
3434
only_fields = ('title', 'content')
3535
interfaces = (relay.Node, )
3636
37+
conversely you can use ``exclude_fields`` meta atrribute.
38+
39+
.. code:: python
40+
41+
from graphene import relay
42+
from graphene_django.types import DjangoObjectType
43+
from .models import Post
44+
45+
class PostNode(DjangoObjectType):
46+
class Meta:
47+
model = Post
48+
exclude_fields = ('published', 'owner')
49+
interfaces = (relay.Node, )
50+
3751
Queryset Filtering On Lists
3852
---------------------------
3953

@@ -108,3 +122,28 @@ method to your ``DjangoObjectType``.
108122
if post.published or context.user == post.owner:
109123
return post
110124
return None
125+
126+
Adding login required
127+
---------------------
128+
129+
If you want to use the standard Django LoginRequiredMixin_ you can create your own view, which includes the ``LoginRequiredMixin`` and subclasses the ``GraphQLView``:
130+
131+
.. code:: python
132+
133+
from django.contrib.auth.mixins import LoginRequiredMixin
134+
from graphene_django.views import GraphQLView
135+
136+
137+
class PrivateGraphQLView(LoginRequiredMixin, GraphQLView):
138+
pass
139+
140+
After this, you can use the new ``PrivateGraphQLView`` in ``urls.py``:
141+
142+
.. code:: python
143+
144+
urlpatterns = [
145+
# some other urls
146+
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
147+
]
148+
149+
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
# General information about the project.
6565
project = u'Graphene Django'
66-
copyright = u'Graphene 2016'
66+
copyright = u'Graphene 2017'
6767
author = u'Syrus Akbary'
6868

6969
# The version info for the project you're documenting, acts as replacement for

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Contents:
66
.. toctree::
77
:maxdepth: 0
88

9-
tutorial
9+
tutorial-plain
10+
tutorial-relay
1011
filtering
1112
authorization
1213
debug

0 commit comments

Comments
 (0)