mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-17 19:52:23 +03:00
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
This commit is contained in:
parent
d478275bca
commit
3d497ea094
|
@ -111,6 +111,7 @@ If you are using ``DjangoObjectType`` you can define a custom `get_queryset`.
|
|||
class PostNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = '__all__'
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
|
|
|
@ -45,6 +45,7 @@ For example:
|
|||
class Meta:
|
||||
# Assume you have an Animal model defined with the following fields
|
||||
model = Animal
|
||||
fields = '__all__'
|
||||
filter_fields = ['name', 'genus', 'is_domesticated']
|
||||
interfaces = (relay.Node, )
|
||||
|
||||
|
@ -75,6 +76,7 @@ You can also make more complex lookup types available:
|
|||
class AnimalNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Animal
|
||||
fields = '__all__'
|
||||
# Provide more complex lookup types
|
||||
filter_fields = {
|
||||
'name': ['exact', 'icontains', 'istartswith'],
|
||||
|
@ -116,6 +118,7 @@ create your own ``FilterSet``. You can pass it directly as follows:
|
|||
class Meta:
|
||||
# Assume you have an Animal model defined with the following fields
|
||||
model = Animal
|
||||
fields = '__all__'
|
||||
filter_fields = ['name', 'genus', 'is_domesticated']
|
||||
interfaces = (relay.Node, )
|
||||
|
||||
|
@ -179,6 +182,7 @@ in unison with the ``filter_fields`` parameter:
|
|||
class AnimalNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Animal
|
||||
fields = '__all__'
|
||||
filterset_class = AnimalFilter
|
||||
interfaces = (relay.Node, )
|
||||
|
||||
|
@ -236,6 +240,7 @@ Extend the tuple of fields if you want to order by more than one field.
|
|||
class Meta:
|
||||
name = 'Group'
|
||||
model = GroupModel
|
||||
fields = '__all__'
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
def resolve_users(self, info, **kwargs):
|
||||
|
|
|
@ -25,6 +25,7 @@ Simple example
|
|||
class QuestionType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class QuestionMutation(graphene.Mutation):
|
||||
|
@ -90,6 +91,7 @@ DjangoModelFormMutation
|
|||
class PetType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Pet
|
||||
fields = '__all__'
|
||||
|
||||
class PetMutation(DjangoModelFormMutation):
|
||||
pet = Field(PetType)
|
||||
|
|
|
@ -28,6 +28,7 @@ Full example
|
|||
class QuestionType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class Query:
|
||||
|
@ -53,6 +54,10 @@ all fields that should be exposed using the fields attribute.
|
|||
This will make it less likely to result in unintentionally exposing data when
|
||||
your models change.
|
||||
|
||||
Setting neither ``fields`` nor ``exclude`` is allowed but will raise a warning, to
|
||||
avoid that you can easily make ``DjangoObjectType`` include all fields in the model as
|
||||
described below.
|
||||
|
||||
``fields``
|
||||
~~~~~~~~~~
|
||||
|
||||
|
@ -127,6 +132,7 @@ For example the following ``Model`` and ``DjangoObjectType``:
|
|||
class Pet(DjangoObjectType):
|
||||
class Meta:
|
||||
model = PetModel
|
||||
fields = '__all__'
|
||||
|
||||
Results in the following GraphQL schema definition:
|
||||
|
||||
|
@ -151,6 +157,7 @@ You can disable this automatic conversion by setting
|
|||
class Pet(DjangoObjectType):
|
||||
class Meta:
|
||||
model = PetModel
|
||||
fields = '__all__'
|
||||
convert_choices_to_enum = False
|
||||
|
||||
.. code::
|
||||
|
@ -168,6 +175,7 @@ automatically converted into enums:
|
|||
class Pet(DjangoObjectType):
|
||||
class Meta:
|
||||
model = PetModel
|
||||
fields = '__all__'
|
||||
convert_choices_to_enum = ['kind']
|
||||
|
||||
**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:
|
|||
class CategoryType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = '__all__'
|
||||
|
||||
.. _django-objecttype-get-queryset:
|
||||
|
||||
|
@ -224,6 +233,7 @@ Use this to control filtering on the ObjectType level instead of the Query objec
|
|||
class QuestionType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
|
@ -347,6 +357,7 @@ the core graphene pages for more information on customizing the Relay experience
|
|||
class QuestionType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
|
||||
|
|
|
@ -8,11 +8,13 @@
|
|||
class CategoryType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class IngredientType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class Query(object):
|
||||
|
|
|
@ -157,11 +157,13 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
|
|||
class CategoryType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class IngredientType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class Query(object):
|
||||
|
|
|
@ -130,6 +130,7 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
|
|||
class CategoryNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = '__all__'
|
||||
filter_fields = ['name', 'ingredients']
|
||||
interfaces = (relay.Node, )
|
||||
|
||||
|
@ -137,6 +138,7 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
|
|||
class IngredientNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
fields = '__all__'
|
||||
# Allow for some more advanced filtering here
|
||||
filter_fields = {
|
||||
'name': ['exact', 'icontains', 'istartswith'],
|
||||
|
|
Loading…
Reference in New Issue
Block a user