File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Types Reference
7
7
8
8
enums
9
9
scalars
10
+ list-and-nonnull
10
11
interfaces
11
12
abstracttypes
12
13
objecttypes
Original file line number Diff line number Diff line change
1
+ Lists and Non-Null
2
+ ==================
3
+
4
+ Object types, scalars, and enums are the only kinds of types you can
5
+ define in Graphene. But when you use the types in other parts of the
6
+ schema, or in your query variable declarations, you can apply additional
7
+ type modifiers that affect validation of those values.
8
+
9
+ NonNull
10
+ -------
11
+
12
+ .. code :: python
13
+
14
+ import graphene
15
+
16
+ class Character (graphene .ObjectType ):
17
+ name = graphene.NonNull(graphene.String)
18
+
19
+
20
+ Here, we're using a ``String `` type and marking it as Non-Null by wrapping
21
+ it using the ``NonNull `` class. This means that our server always expects
22
+ to return a non-null value for this field, and if it ends up getting a
23
+ null value that will actually trigger a GraphQL execution error,
24
+ letting the client know that something has gone wrong.
25
+
26
+
27
+ The previous ``NonNull `` code snippet is also equivalent to:
28
+
29
+ .. code :: python
30
+
31
+ import graphene
32
+
33
+ class Character (graphene .ObjectType ):
34
+ name = graphene.String(required = True )
35
+
36
+
37
+ List
38
+ ----
39
+
40
+ .. code :: python
41
+
42
+ import graphene
43
+
44
+ class Character (graphene .ObjectType ):
45
+ appears_in = graphene.List(graphene.String)
46
+
47
+ Lists work in a similar way: We can use a type modifier to mark a type as a
48
+ ``List ``, which indicates that this field will return a list of that type.
49
+ It works the same for arguments, where the validation step will expect a list
50
+ for that value.
You can’t perform that action at this time.
0 commit comments