mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-01 00:17:26 +03:00 
			
		
		
		
	Merge pull request #467 from affablebloke/master
Added type consistency between Field and Argument
This commit is contained in:
		
						commit
						fccc22b651
					
				|  | @ -4,6 +4,7 @@ from itertools import chain | |||
| from .mountedtype import MountedType | ||||
| from .structures import NonNull | ||||
| from .dynamic import Dynamic | ||||
| from .utils import get_type | ||||
| 
 | ||||
| 
 | ||||
| class Argument(MountedType): | ||||
|  | @ -15,10 +16,14 @@ class Argument(MountedType): | |||
|             type = NonNull(type) | ||||
| 
 | ||||
|         self.name = name | ||||
|         self.type = type | ||||
|         self._type = type | ||||
|         self.default_value = default_value | ||||
|         self.description = description | ||||
| 
 | ||||
|     @property | ||||
|     def type(self): | ||||
|         return get_type(self._type) | ||||
| 
 | ||||
|     def __eq__(self, other): | ||||
|         return isinstance(other, Argument) and ( | ||||
|             self.name == other.name, | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| import pytest | ||||
| from functools import partial | ||||
| 
 | ||||
| from ..argument import Argument, to_arguments | ||||
| from ..field import Field | ||||
|  | @ -48,7 +49,7 @@ def test_to_arguments_raises_if_field(): | |||
| 
 | ||||
|     with pytest.raises(ValueError) as exc_info: | ||||
|         to_arguments(args) | ||||
|      | ||||
| 
 | ||||
|     assert str(exc_info.value) == 'Expected arg_string to be Argument, but received Field. Try using Argument(String).' | ||||
| 
 | ||||
| 
 | ||||
|  | @ -59,5 +60,17 @@ def test_to_arguments_raises_if_inputfield(): | |||
| 
 | ||||
|     with pytest.raises(ValueError) as exc_info: | ||||
|         to_arguments(args) | ||||
|      | ||||
| 
 | ||||
|     assert str(exc_info.value) == 'Expected arg_string to be Argument, but received InputField. Try using Argument(String).' | ||||
| 
 | ||||
| 
 | ||||
| def test_argument_with_lazy_type(): | ||||
|     MyType = object() | ||||
|     arg = Argument(lambda: MyType) | ||||
|     assert arg.type == MyType | ||||
| 
 | ||||
| 
 | ||||
| def test_argument_with_lazy_partial_type(): | ||||
|     MyType = object() | ||||
|     arg = Argument(partial(lambda: MyType)) | ||||
|     assert arg.type == MyType | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user