Skip to content

Commit 3d497ea

Browse files
committed
Update docs to take new warning into account
* all examples have fields or exclude set * mention that if neither fields nor exclude is used, warning will be raised
1 parent d478275 commit 3d497ea

File tree

7 files changed

+25
-0
lines changed

7 files changed

+25
-0
lines changed

docs/authorization.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you are using ``DjangoObjectType`` you can define a custom `get_queryset`.
111111
class PostNode(DjangoObjectType):
112112
class Meta:
113113
model = Post
114+
fields = '__all__'
114115
115116
@classmethod
116117
def get_queryset(cls, queryset, info):

docs/filtering.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ For example:
4545
class Meta:
4646
# Assume you have an Animal model defined with the following fields
4747
model = Animal
48+
fields = '__all__'
4849
filter_fields = ['name', 'genus', 'is_domesticated']
4950
interfaces = (relay.Node, )
5051
@@ -75,6 +76,7 @@ You can also make more complex lookup types available:
7576
class AnimalNode(DjangoObjectType):
7677
class Meta:
7778
model = Animal
79+
fields = '__all__'
7880
# Provide more complex lookup types
7981
filter_fields = {
8082
'name': ['exact', 'icontains', 'istartswith'],
@@ -116,6 +118,7 @@ create your own ``FilterSet``. You can pass it directly as follows:
116118
class Meta:
117119
# Assume you have an Animal model defined with the following fields
118120
model = Animal
121+
fields = '__all__'
119122
filter_fields = ['name', 'genus', 'is_domesticated']
120123
interfaces = (relay.Node, )
121124
@@ -179,6 +182,7 @@ in unison with the ``filter_fields`` parameter:
179182
class AnimalNode(DjangoObjectType):
180183
class Meta:
181184
model = Animal
185+
fields = '__all__'
182186
filterset_class = AnimalFilter
183187
interfaces = (relay.Node, )
184188
@@ -236,6 +240,7 @@ Extend the tuple of fields if you want to order by more than one field.
236240
class Meta:
237241
name = 'Group'
238242
model = GroupModel
243+
fields = '__all__'
239244
interfaces = (relay.Node,)
240245
241246
def resolve_users(self, info, **kwargs):

docs/mutations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Simple example
2525
class QuestionType(DjangoObjectType):
2626
class Meta:
2727
model = Question
28+
fields = '__all__'
2829
2930
3031
class QuestionMutation(graphene.Mutation):
@@ -90,6 +91,7 @@ DjangoModelFormMutation
9091
class PetType(DjangoObjectType):
9192
class Meta:
9293
model = Pet
94+
fields = '__all__'
9395
9496
class PetMutation(DjangoModelFormMutation):
9597
pet = Field(PetType)

docs/queries.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Full example
2828
class QuestionType(DjangoObjectType):
2929
class Meta:
3030
model = Question
31+
fields = '__all__'
3132
3233
3334
class Query:
@@ -53,6 +54,10 @@ all fields that should be exposed using the fields attribute.
5354
This will make it less likely to result in unintentionally exposing data when
5455
your models change.
5556

57+
Setting neither ``fields`` nor ``exclude`` is allowed but will raise a warning, to
58+
avoid that you can easily make ``DjangoObjectType`` include all fields in the model as
59+
described below.
60+
5661
``fields``
5762
~~~~~~~~~~
5863

@@ -127,6 +132,7 @@ For example the following ``Model`` and ``DjangoObjectType``:
127132
class Pet(DjangoObjectType):
128133
class Meta:
129134
model = PetModel
135+
fields = '__all__'
130136
131137
Results in the following GraphQL schema definition:
132138

@@ -151,6 +157,7 @@ You can disable this automatic conversion by setting
151157
class Pet(DjangoObjectType):
152158
class Meta:
153159
model = PetModel
160+
fields = '__all__'
154161
convert_choices_to_enum = False
155162
156163
.. code::
@@ -168,6 +175,7 @@ automatically converted into enums:
168175
class Pet(DjangoObjectType):
169176
class Meta:
170177
model = PetModel
178+
fields = '__all__'
171179
convert_choices_to_enum = ['kind']
172180
173181
**Note:** Setting ``convert_choices_to_enum = []`` is the same as setting it to
@@ -206,6 +214,7 @@ need to create the most basic class for this to work:
206214
class CategoryType(DjangoObjectType):
207215
class Meta:
208216
model = Category
217+
fields = '__all__'
209218
210219
.. _django-objecttype-get-queryset:
211220

@@ -224,6 +233,7 @@ Use this to control filtering on the ObjectType level instead of the Query objec
224233
class QuestionType(DjangoObjectType):
225234
class Meta:
226235
model = Question
236+
fields = '__all__'
227237
228238
@classmethod
229239
def get_queryset(cls, queryset, info):
@@ -347,6 +357,7 @@ the core graphene pages for more information on customizing the Relay experience
347357
class QuestionType(DjangoObjectType):
348358
class Meta:
349359
model = Question
360+
fields = '__all__'
350361
interfaces = (relay.Node,)
351362
352363

docs/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
class CategoryType(DjangoObjectType):
99
class Meta:
1010
model = Category
11+
fields = '__all__'
1112

1213

1314
class IngredientType(DjangoObjectType):
1415
class Meta:
1516
model = Ingredient
17+
fields = '__all__'
1618

1719

1820
class Query(object):

docs/tutorial-plain.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
157157
class CategoryType(DjangoObjectType):
158158
class Meta:
159159
model = Category
160+
fields = '__all__'
160161
161162
162163
class IngredientType(DjangoObjectType):
163164
class Meta:
164165
model = Ingredient
166+
fields = '__all__'
165167
166168
167169
class Query(object):

docs/tutorial-relay.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
130130
class CategoryNode(DjangoObjectType):
131131
class Meta:
132132
model = Category
133+
fields = '__all__'
133134
filter_fields = ['name', 'ingredients']
134135
interfaces = (relay.Node, )
135136
136137
137138
class IngredientNode(DjangoObjectType):
138139
class Meta:
139140
model = Ingredient
141+
fields = '__all__'
140142
# Allow for some more advanced filtering here
141143
filter_fields = {
142144
'name': ['exact', 'icontains', 'istartswith'],

0 commit comments

Comments
 (0)