diff --git a/docs/authorization.rst b/docs/authorization.rst index 8ef05b4..387ad29 100644 --- a/docs/authorization.rst +++ b/docs/authorization.rst @@ -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): diff --git a/docs/filtering.rst b/docs/filtering.rst index a511c64..9fff8eb 100644 --- a/docs/filtering.rst +++ b/docs/filtering.rst @@ -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): diff --git a/docs/mutations.rst b/docs/mutations.rst index aef32eb..3069322 100644 --- a/docs/mutations.rst +++ b/docs/mutations.rst @@ -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) diff --git a/docs/queries.rst b/docs/queries.rst index 4b3f718..9969373 100644 --- a/docs/queries.rst +++ b/docs/queries.rst @@ -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,) diff --git a/docs/schema.py b/docs/schema.py index 3d9b2fa..1de92ed 100644 --- a/docs/schema.py +++ b/docs/schema.py @@ -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): diff --git a/docs/tutorial-plain.rst b/docs/tutorial-plain.rst index e80f9ab..0547ada 100644 --- a/docs/tutorial-plain.rst +++ b/docs/tutorial-plain.rst @@ -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): diff --git a/docs/tutorial-relay.rst b/docs/tutorial-relay.rst index e900ea1..4baba8b 100644 --- a/docs/tutorial-relay.rst +++ b/docs/tutorial-relay.rst @@ -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'],