Update docs

This commit is contained in:
Jonathan Kim 2019-06-25 16:50:43 +01:00
parent 64bc6c7c2e
commit 09402441fd

View File

@ -41,14 +41,18 @@ Full example
return Question.objects.get(pk=question_id) return Question.objects.get(pk=question_id)
Fields Specifying which fields to include
------ ----------------------------------
By default, ``DjangoObjectType`` will present all fields on a Model through GraphQL. By default, ``DjangoObjectType`` will present all fields on a Model through GraphQL.
If you don't want to do this you can change this by setting either ``only_fields`` and ``exclude_fields``. If you only want a subset of fields to be present, you can do so using
``fields`` or ``exclude``. It is strongly recommended that you explicitly set
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.
only_fields ``fields``
~~~~~~~~~~~ ~~~~~~~~~~
Show **only** these fields on the model: Show **only** these fields on the model:
@ -57,24 +61,24 @@ Show **only** these fields on the model:
class QuestionType(DjangoObjectType): class QuestionType(DjangoObjectType):
class Meta: class Meta:
model = Question model = Question
only_fields = ('question_text') fields = ('id', 'question_text')
exclude_fields ``exclude``
~~~~~~~~~~~~~~ ~~~~~~~~~~~
Show all fields **except** those in ``exclude_fields``: Show all fields **except** those in ``exclude``:
.. code:: python .. code:: python
class QuestionType(DjangoObjectType): class QuestionType(DjangoObjectType):
class Meta: class Meta:
model = Question model = Question
exclude_fields = ('question_text') exclude = ('question_text')
Customised fields Customising fields
~~~~~~~~~~~~~~~~~ ------------------
You can completely overwrite a field, or add new fields, to a ``DjangoObjectType`` using a Resolver: You can completely overwrite a field, or add new fields, to a ``DjangoObjectType`` using a Resolver:
@ -178,7 +182,7 @@ When ``Question`` is published as a ``DjangoObjectType`` and you want to add ``C
class QuestionType(DjangoObjectType): class QuestionType(DjangoObjectType):
class Meta: class Meta:
model = Question model = Question
only_fields = ('category',) fields = ('category',)
Then all query-able related models must be defined as DjangoObjectType subclass, Then all query-able related models must be defined as DjangoObjectType subclass,
or they will fail to show if you are trying to query those relation fields. You only or they will fail to show if you are trying to query those relation fields. You only