mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Added partial support to Dynamic type (#725)
This commit is contained in:
		
							parent
							
								
									28f6353212
								
							
						
					
					
						commit
						034765aebe
					
				|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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' | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user