Skip to content

Commit e2cdd80

Browse files
committed
Added docs for List and NonNull types. Fixed #326
1 parent 81a2ed0 commit e2cdd80

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/types/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Types Reference
77

88
enums
99
scalars
10+
list-and-nonnull
1011
interfaces
1112
abstracttypes
1213
objecttypes

docs/types/list-and-nonnull.rst

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.

0 commit comments

Comments
 (0)