You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Graphene-Django provides some useful fields to help integrate Django with your GraphQL
5
+
Schema.
6
+
7
+
DjangoListField
8
+
---------------
9
+
10
+
``DjangoListField`` allows you to define a list of :ref:`DjangoObjectType<queries-objecttypes>`'s. By default it will resolve the default queryset of the Django model.
11
+
12
+
.. code:: python
13
+
14
+
from graphene import ObjectType, Schema
15
+
from graphene_django import DjangoListField
16
+
17
+
classRecipeType(DjangoObjectType):
18
+
classMeta:
19
+
model = Recipe
20
+
fields = ("title", "instructions")
21
+
22
+
classQuery(ObjectType):
23
+
recipes = DjangoListField(RecipeType)
24
+
25
+
schema = Schema(query=Query)
26
+
27
+
The above code results in the following schema definition:
28
+
29
+
.. code::
30
+
31
+
schema {
32
+
query: Query
33
+
}
34
+
35
+
type Query {
36
+
recipes: [RecipeType!]
37
+
}
38
+
39
+
type RecipeType {
40
+
title: String!
41
+
instructions: String!
42
+
}
43
+
44
+
Custom resolvers
45
+
****************
46
+
47
+
If your ``DjangoObjectType`` has defined a custom
48
+
:ref:`get_queryset<django-objecttype-get-queryset>` method, when resolving a
49
+
``DjangoListField`` it will be called with either the return of the field
50
+
resolver (if one is defined) or the default queryeset from the Django model.
51
+
52
+
For example the following schema will only resolve recipes which have been
0 commit comments