mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Improved object container initialization. Fixed #585
This commit is contained in:
parent
045d5fffbe
commit
3ee94131ae
|
@ -81,7 +81,7 @@ class ObjectType(BaseType):
|
||||||
|
|
||||||
for name, field in fields_iter:
|
for name, field in fields_iter:
|
||||||
try:
|
try:
|
||||||
val = kwargs.pop(name)
|
val = kwargs.pop(name, None)
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -105,3 +105,31 @@ def test_mutation_execution():
|
||||||
'dynamic': 'dynamic',
|
'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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ from ..interface import Interface
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..unmountedtype import UnmountedType
|
from ..unmountedtype import UnmountedType
|
||||||
from ..structures import NonNull
|
from ..structures import NonNull
|
||||||
|
from ..scalars import String
|
||||||
|
from ..schema import Schema
|
||||||
|
|
||||||
|
|
||||||
class MyType(Interface):
|
class MyType(Interface):
|
||||||
|
@ -224,3 +226,29 @@ def test_objecttype_with_possible_types_and_is_type_of_should_raise():
|
||||||
'MyObjectType.Meta.possible_types will cause type collision with '
|
'MyObjectType.Meta.possible_types will cause type collision with '
|
||||||
'MyObjectType.is_type_of. Please use one or other.'
|
'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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user