1
+ from django .db import models
2
+ from graphene import Field
3
+ from graphene .types .inputobjecttype import InputObjectType
1
4
from py .test import raises
2
5
from rest_framework import serializers
3
6
7
+ from ...types import DjangoObjectType
4
8
from ..mutation import SerializerMutation
5
9
6
10
11
+ class MyFakeModel (models .Model ):
12
+ cool_name = models .CharField (max_length = 50 )
13
+
14
+
15
+ class MyModelSerializer (serializers .ModelSerializer ):
16
+ class Meta :
17
+ model = MyFakeModel
18
+ fields = '__all__'
19
+
20
+
7
21
class MySerializer (serializers .Serializer ):
8
22
text = serializers .CharField ()
23
+ model = MyModelSerializer ()
9
24
10
25
11
26
def test_needs_serializer_class ():
@@ -22,6 +37,7 @@ class Meta:
22
37
serializer_class = MySerializer
23
38
24
39
assert 'text' in MyMutation ._meta .fields
40
+ assert 'model' in MyMutation ._meta .fields
25
41
assert 'errors' in MyMutation ._meta .fields
26
42
27
43
@@ -31,5 +47,24 @@ class Meta:
31
47
serializer_class = MySerializer
32
48
33
49
assert 'text' in MyMutation .Input ._meta .fields
50
+ assert 'model' in MyMutation .Input ._meta .fields
51
+
52
+
53
+ def test_nested_model ():
54
+
55
+ class MyFakeModelGrapheneType (DjangoObjectType ):
56
+ class Meta :
57
+ model = MyFakeModel
58
+
59
+ class MyMutation (SerializerMutation ):
60
+ class Meta :
61
+ serializer_class = MySerializer
34
62
63
+ model_field = MyMutation ._meta .fields ['model' ]
64
+ assert isinstance (model_field , Field )
65
+ assert model_field .type == MyFakeModelGrapheneType
35
66
67
+ model_input = MyMutation .Input ._meta .fields ['model' ]
68
+ model_input_type = model_input ._type .of_type
69
+ assert issubclass (model_input_type , InputObjectType )
70
+ assert 'cool_name' in model_input_type ._meta .fields
0 commit comments