Skip to content

Commit

Permalink
Improved object container initialization. Fixed #585
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 3, 2017
1 parent 045d5ff commit 3ee9413
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphene/types/objecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, *args, **kwargs):

for name, field in fields_iter:
try:
val = kwargs.pop(name)
val = kwargs.pop(name, None)
setattr(self, name, val)
except KeyError:
pass
Expand Down
28 changes: 28 additions & 0 deletions graphene/types/tests/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,31 @@ class MyMutation(ObjectType):
'dynamic': 'dynamic',
}
}


def test_mutation_no_fields_output():
class CreateUser(Mutation):
name = String()

def mutate(self, info):
return CreateUser()

class Query(ObjectType):
a = String()

class MyMutation(ObjectType):
create_user = CreateUser.Field()

schema = Schema(query=Query, mutation=MyMutation)
result = schema.execute(''' mutation mymutation {
createUser {
name
}
}
''')
assert not result.errors
assert result.data == {
'createUser': {
'name': None,
}
}
28 changes: 28 additions & 0 deletions graphene/types/tests/test_objecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from ..objecttype import ObjectType
from ..unmountedtype import UnmountedType
from ..structures import NonNull
from ..scalars import String
from ..schema import Schema


class MyType(Interface):
Expand Down Expand Up @@ -224,3 +226,29 @@ def is_type_of(cls, root, context, info):
'MyObjectType.Meta.possible_types will cause type collision with '
'MyObjectType.is_type_of. Please use one or other.'
)


def test_objecttype_no_fields_output():
class User(ObjectType):
name = String()

class Query(ObjectType):
user = Field(User)

def resolve_user(self, info):
return User()


schema = Schema(query=Query)
result = schema.execute(''' query basequery {
user {
name
}
}
''')
assert not result.errors
assert result.data == {
'user': {
'name': None,
}
}

0 comments on commit 3ee9413

Please sign in to comment.