diff --git a/graphene/types/dynamic.py b/graphene/types/dynamic.py index 6c4092f0..0efbd081 100644 --- a/graphene/types/dynamic.py +++ b/graphene/types/dynamic.py @@ -1,4 +1,5 @@ import inspect +from functools import partial from .mountedtype import MountedType @@ -11,7 +12,7 @@ class Dynamic(MountedType): def __init__(self, type, with_schema=False, _creation_counter=None): super(Dynamic, self).__init__(_creation_counter=_creation_counter) - assert inspect.isfunction(type) + assert inspect.isfunction(type) or isinstance(type, partial) self.type = type self.with_schema = with_schema diff --git a/graphene/types/tests/test_dynamic.py b/graphene/types/tests/test_dynamic.py index 4e72395f..b31ccf4b 100644 --- a/graphene/types/tests/test_dynamic.py +++ b/graphene/types/tests/test_dynamic.py @@ -1,3 +1,4 @@ +from functools import partial from ..dynamic import Dynamic from ..scalars import String from ..structures import List, NonNull @@ -25,3 +26,11 @@ def test_list_non_null(): dynamic = Dynamic(lambda: List(NonNull(String))) assert dynamic.get_type().of_type.of_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'