2
2
3
3
from ..mutation import Mutation
4
4
from ..objecttype import ObjectType
5
+ from ..schema import Schema
6
+ from ..scalars import String
5
7
6
8
7
9
def test_generate_mutation_no_args ():
@@ -17,26 +19,6 @@ def mutate(cls, *args, **kwargs):
17
19
assert MyMutation .Field ().resolver == MyMutation .mutate
18
20
19
21
20
- # def test_generate_mutation_with_args():
21
- # class MyMutation(Mutation):
22
- # '''Documentation'''
23
- # class Input:
24
- # s = String()
25
-
26
- # @classmethod
27
- # def mutate(cls, *args, **kwargs):
28
- # pass
29
-
30
- # graphql_type = MyMutation._meta.graphql_type
31
- # field = MyMutation.Field()
32
- # assert graphql_type.name == "MyMutation"
33
- # assert graphql_type.description == "Documentation"
34
- # assert isinstance(field, Field)
35
- # assert field.type == MyMutation._meta.graphql_type
36
- # assert 's' in field.args
37
- # assert field.args['s'].type == String
38
-
39
-
40
22
def test_generate_mutation_with_meta ():
41
23
class MyMutation (Mutation ):
42
24
@@ -59,3 +41,35 @@ class MyMutation(Mutation):
59
41
pass
60
42
61
43
assert "All mutations must define a mutate method in it" == str (excinfo .value )
44
+
45
+
46
+ def test_mutation_execution ():
47
+ class CreateUser (Mutation ):
48
+ class Input :
49
+ name = String ()
50
+
51
+ name = String ()
52
+
53
+ def mutate (self , args , context , info ):
54
+ name = args .get ('name' )
55
+ return CreateUser (name = name )
56
+
57
+ class Query (ObjectType ):
58
+ a = String ()
59
+
60
+ class MyMutation (ObjectType ):
61
+ create_user = CreateUser .Field ()
62
+
63
+ schema = Schema (query = Query , mutation = MyMutation )
64
+ result = schema .execute (''' mutation mymutation {
65
+ createUser(name:"Peter") {
66
+ name
67
+ }
68
+ }
69
+ ''' )
70
+ assert not result .errors
71
+ assert result .data == {
72
+ 'createUser' : {
73
+ 'name' : "Peter"
74
+ }
75
+ }
0 commit comments