22
33from ..mutation import Mutation
44from ..objecttype import ObjectType
5+ from ..schema import Schema
6+ from ..scalars import String
57
68
79def test_generate_mutation_no_args ():
@@ -17,26 +19,6 @@ def mutate(cls, *args, **kwargs):
1719 assert MyMutation .Field ().resolver == MyMutation .mutate
1820
1921
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-
4022def test_generate_mutation_with_meta ():
4123 class MyMutation (Mutation ):
4224
@@ -59,3 +41,35 @@ class MyMutation(Mutation):
5941 pass
6042
6143 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