Skip to content

Commit fccc22b

Browse files
authored
Merge pull request #467 from affablebloke/master
Added type consistency between Field and Argument
2 parents 8622989 + 83857bf commit fccc22b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

graphene/types/argument.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .mountedtype import MountedType
55
from .structures import NonNull
66
from .dynamic import Dynamic
7+
from .utils import get_type
78

89

910
class Argument(MountedType):
@@ -15,10 +16,14 @@ def __init__(self, type, default_value=None, description=None, name=None, requir
1516
type = NonNull(type)
1617

1718
self.name = name
18-
self.type = type
19+
self._type = type
1920
self.default_value = default_value
2021
self.description = description
2122

23+
@property
24+
def type(self):
25+
return get_type(self._type)
26+
2227
def __eq__(self, other):
2328
return isinstance(other, Argument) and (
2429
self.name == other.name,

graphene/types/tests/test_argument.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from functools import partial
23

34
from ..argument import Argument, to_arguments
45
from ..field import Field
@@ -48,7 +49,7 @@ def test_to_arguments_raises_if_field():
4849

4950
with pytest.raises(ValueError) as exc_info:
5051
to_arguments(args)
51-
52+
5253
assert str(exc_info.value) == 'Expected arg_string to be Argument, but received Field. Try using Argument(String).'
5354

5455

@@ -59,5 +60,17 @@ def test_to_arguments_raises_if_inputfield():
5960

6061
with pytest.raises(ValueError) as exc_info:
6162
to_arguments(args)
62-
63+
6364
assert str(exc_info.value) == 'Expected arg_string to be Argument, but received InputField. Try using Argument(String).'
65+
66+
67+
def test_argument_with_lazy_type():
68+
MyType = object()
69+
arg = Argument(lambda: MyType)
70+
assert arg.type == MyType
71+
72+
73+
def test_argument_with_lazy_partial_type():
74+
MyType = object()
75+
arg = Argument(partial(lambda: MyType))
76+
assert arg.type == MyType

0 commit comments

Comments
 (0)