Skip to content

Commit 3ee9413

Browse files
committed
Improved object container initialization. Fixed #585
1 parent 045d5ff commit 3ee9413

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

graphene/types/objecttype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, *args, **kwargs):
8181

8282
for name, field in fields_iter:
8383
try:
84-
val = kwargs.pop(name)
84+
val = kwargs.pop(name, None)
8585
setattr(self, name, val)
8686
except KeyError:
8787
pass

graphene/types/tests/test_mutation.py

+28
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,31 @@ class MyMutation(ObjectType):
105105
'dynamic': 'dynamic',
106106
}
107107
}
108+
109+
110+
def test_mutation_no_fields_output():
111+
class CreateUser(Mutation):
112+
name = String()
113+
114+
def mutate(self, info):
115+
return CreateUser()
116+
117+
class Query(ObjectType):
118+
a = String()
119+
120+
class MyMutation(ObjectType):
121+
create_user = CreateUser.Field()
122+
123+
schema = Schema(query=Query, mutation=MyMutation)
124+
result = schema.execute(''' mutation mymutation {
125+
createUser {
126+
name
127+
}
128+
}
129+
''')
130+
assert not result.errors
131+
assert result.data == {
132+
'createUser': {
133+
'name': None,
134+
}
135+
}

graphene/types/tests/test_objecttype.py

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from ..objecttype import ObjectType
66
from ..unmountedtype import UnmountedType
77
from ..structures import NonNull
8+
from ..scalars import String
9+
from ..schema import Schema
810

911

1012
class MyType(Interface):
@@ -224,3 +226,29 @@ def is_type_of(cls, root, context, info):
224226
'MyObjectType.Meta.possible_types will cause type collision with '
225227
'MyObjectType.is_type_of. Please use one or other.'
226228
)
229+
230+
231+
def test_objecttype_no_fields_output():
232+
class User(ObjectType):
233+
name = String()
234+
235+
class Query(ObjectType):
236+
user = Field(User)
237+
238+
def resolve_user(self, info):
239+
return User()
240+
241+
242+
schema = Schema(query=Query)
243+
result = schema.execute(''' query basequery {
244+
user {
245+
name
246+
}
247+
}
248+
''')
249+
assert not result.errors
250+
assert result.data == {
251+
'user': {
252+
'name': None,
253+
}
254+
}

0 commit comments

Comments
 (0)