Skip to content

Commit a9e5beb

Browse files
committed
Merge branch 'master' into form_mutations
# Conflicts: # graphene_django/forms/converter.py # graphene_django/forms/tests/test_converter.py
2 parents c3938d1 + 205c177 commit a9e5beb

Some content is hidden

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

48 files changed

+1187
-239
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ install:
1111
pip install -e .[test]
1212
pip install psycopg2 # Required for Django postgres fields testing
1313
pip install django==$DJANGO_VERSION
14+
if (($(echo "$DJANGO_VERSION <= 1.9" | bc -l))); then # DRF dropped 1.8 and 1.9 support at 3.7.0
15+
pip install djangorestframework==3.6.4
16+
fi
1417
python setup.py develop
1518
elif [ "$TEST_TYPE" = lint ]; then
1619
pip install flake8

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016-Present Syrus Akbary
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include README.md
1+
include README.md LICENSE
22
recursive-include graphene_django/templates *

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ A [Django](https://www.djangoproject.com/) integration for [Graphene](http://gra
99

1010
## Installation
1111

12-
For instaling graphene, just run this command in your shell
12+
For installing graphene, just run this command in your shell
1313

1414
```bash
15-
pip install "graphene-django>=2.0.dev"
15+
pip install "graphene-django>=2.0"
1616
```
1717

1818
### Settings
@@ -67,8 +67,7 @@ class User(DjangoObjectType):
6767
class Query(graphene.ObjectType):
6868
users = graphene.List(User)
6969

70-
@graphene.resolve_only_args
71-
def resolve_users(self):
70+
def resolve_users(self, info):
7271
return UserModel.objects.all()
7372

7473
schema = graphene.Schema(query=Query)

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ A `Django <https://www.djangoproject.com/>`__ integration for
1313
Installation
1414
------------
1515

16-
For instaling graphene, just run this command in your shell
16+
For installing graphene, just run this command in your shell
1717

1818
.. code:: bash
1919
20-
pip install "graphene-django>=2.0.dev"
20+
pip install "graphene-django>=2.0"
2121
2222
Settings
2323
~~~~~~~~

django_test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
INSTALLED_APPS = [
1010
'graphene_django',
11+
'graphene_django.rest_framework',
1112
'graphene_django.tests',
1213
'starwars',
1314
]

docs/authorization.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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.
37+
conversely you can use ``exclude_fields`` meta attribute.
3838

3939
.. code:: python
4040
@@ -61,7 +61,7 @@ define a resolve method for that field and return the desired queryset.
6161
from .models import Post
6262
6363
class Query(ObjectType):
64-
all_posts = DjangoFilterConnectionField(CategoryNode)
64+
all_posts = DjangoFilterConnectionField(PostNode)
6565
6666
def resolve_all_posts(self, args, info):
6767
return Post.objects.filter(published=True)
@@ -79,14 +79,14 @@ with the context argument.
7979
from .models import Post
8080
8181
class Query(ObjectType):
82-
my_posts = DjangoFilterConnectionField(CategoryNode)
82+
my_posts = DjangoFilterConnectionField(PostNode)
8383
84-
def resolve_my_posts(self, args, context, info):
84+
def resolve_my_posts(self, info):
8585
# context will reference to the Django request
86-
if not context.user.is_authenticated():
86+
if not info.context.user.is_authenticated():
8787
return Post.objects.none()
8888
else:
89-
return Post.objects.filter(owner=context.user)
89+
return Post.objects.filter(owner=info.context.user)
9090
9191
If you're using your own view, passing the request context into the
9292
schema is simple.

docs/filtering.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,23 @@ create your own ``Filterset`` as follows:
126126
# We specify our custom AnimalFilter using the filterset_class param
127127
all_animals = DjangoFilterConnectionField(AnimalNode,
128128
filterset_class=AnimalFilter)
129+
130+
The context argument is passed on as the `request argument <http://django-filter.readthedocs.io/en/latest/guide/usage.html#request-based-filtering>`__
131+
in a ``django_filters.FilterSet`` instance. You can use this to customize your
132+
filters to be context-dependent. We could modify the ``AnimalFilter`` above to
133+
pre-filter animals owned by the authenticated user (set in ``context.user``).
134+
135+
.. code:: python
136+
137+
class AnimalFilter(django_filters.FilterSet):
138+
# Do case-insensitive lookups on 'name'
139+
name = django_filters.CharFilter(lookup_type='iexact')
140+
141+
class Meta:
142+
model = Animal
143+
fields = ['name', 'genus', 'is_domesticated']
144+
145+
@property
146+
def qs(self):
147+
# The query context can be found in self.request.
148+
return super(AnimalFilter, self).qs.filter(owner=self.request.user)

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
sphinx
22
# Docs template
3-
https://github.com/graphql-python/graphene-python.org/archive/docs.zip
3+
http://graphene-python.org/sphinx_graphene_theme.zip

docs/rest-framework.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,50 @@ You can create a Mutation based on a serializer by using the
1919
class Meta:
2020
serializer_class = MySerializer
2121
22+
Create/Update Operations
23+
---------------------
24+
25+
By default ModelSerializers accept create and update operations. To
26+
customize this use the `model_operations` attribute. The update
27+
operation looks up models by the primary key by default. You can
28+
customize the look up with the lookup attribute.
29+
30+
Other default attributes:
31+
32+
`partial = False`: Accept updates without all the input fields.
33+
34+
.. code:: python
35+
36+
from graphene_django.rest_framework.mutation import SerializerMutation
37+
38+
class AwesomeModelMutation(SerializerMutation):
39+
class Meta:
40+
serializer_class = MyModelSerializer
41+
model_operations = ['create', 'update']
42+
lookup_field = 'id'
43+
44+
Overriding Update Queries
45+
-------------------------
46+
47+
Use the method `get_serializer_kwargs` to override how
48+
updates are applied.
49+
50+
.. code:: python
51+
52+
from graphene_django.rest_framework.mutation import SerializerMutation
53+
54+
class AwesomeModelMutation(SerializerMutation):
55+
class Meta:
56+
serializer_class = MyModelSerializer
57+
58+
@classmethod
59+
def get_serializer_kwargs(cls, root, info, **input):
60+
if 'id' in input:
61+
instance = Post.objects.filter(id=input['id'], owner=info.context.user).first()
62+
if instance:
63+
return {'instance': instance, 'data': input, 'partial': True}
64+
65+
else:
66+
raise http.Http404
67+
68+
return {'data': input, 'partial': True}

0 commit comments

Comments
 (0)