Added partial support to Dynamic type (#725)

This commit is contained in:
Nikordaris 2018-05-25 09:20:22 -06:00 committed by Jonathan Kim
parent 28f6353212
commit 034765aebe
2 changed files with 11 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import inspect import inspect
from functools import partial
from .mountedtype import MountedType from .mountedtype import MountedType
@ -11,7 +12,7 @@ class Dynamic(MountedType):
def __init__(self, type, with_schema=False, _creation_counter=None): def __init__(self, type, with_schema=False, _creation_counter=None):
super(Dynamic, self).__init__(_creation_counter=_creation_counter) super(Dynamic, self).__init__(_creation_counter=_creation_counter)
assert inspect.isfunction(type) assert inspect.isfunction(type) or isinstance(type, partial)
self.type = type self.type = type
self.with_schema = with_schema self.with_schema = with_schema

View File

@ -1,3 +1,4 @@
from functools import partial
from ..dynamic import Dynamic from ..dynamic import Dynamic
from ..scalars import String from ..scalars import String
from ..structures import List, NonNull from ..structures import List, NonNull
@ -25,3 +26,11 @@ def test_list_non_null():
dynamic = Dynamic(lambda: List(NonNull(String))) dynamic = Dynamic(lambda: List(NonNull(String)))
assert dynamic.get_type().of_type.of_type == String assert dynamic.get_type().of_type.of_type == String
assert str(dynamic.get_type()) == '[String!]' assert str(dynamic.get_type()) == '[String!]'
def test_partial():
def __type(_type):
return _type
dynamic = Dynamic(partial(__type, String))
assert dynamic.get_type() == String
assert str(dynamic.get_type()) == 'String'