Skip to content

Commit 034765a

Browse files
nikordarisjkimbo
authored andcommitted
Added partial support to Dynamic type (#725)
1 parent 28f6353 commit 034765a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

graphene/types/dynamic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
from functools import partial
23

34
from .mountedtype import MountedType
45

@@ -11,7 +12,7 @@ class Dynamic(MountedType):
1112

1213
def __init__(self, type, with_schema=False, _creation_counter=None):
1314
super(Dynamic, self).__init__(_creation_counter=_creation_counter)
14-
assert inspect.isfunction(type)
15+
assert inspect.isfunction(type) or isinstance(type, partial)
1516
self.type = type
1617
self.with_schema = with_schema
1718

graphene/types/tests/test_dynamic.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from functools import partial
12
from ..dynamic import Dynamic
23
from ..scalars import String
34
from ..structures import List, NonNull
@@ -25,3 +26,11 @@ def test_list_non_null():
2526
dynamic = Dynamic(lambda: List(NonNull(String)))
2627
assert dynamic.get_type().of_type.of_type == String
2728
assert str(dynamic.get_type()) == '[String!]'
29+
30+
31+
def test_partial():
32+
def __type(_type):
33+
return _type
34+
dynamic = Dynamic(partial(__type, String))
35+
assert dynamic.get_type() == String
36+
assert str(dynamic.get_type()) == 'String'

0 commit comments

Comments
 (0)