Skip to content

Commit

Permalink
Use default_resolver to resolve values when using the source at… (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo committed Mar 16, 2020
1 parent 6f2863e commit cb3bfe0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion graphene/types/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .argument import Argument, to_arguments
from .mountedtype import MountedType
from .resolver import default_resolver
from .structures import NonNull
from .unmountedtype import UnmountedType
from .utils import get_type
Expand All @@ -12,7 +13,7 @@


def source_resolver(source, root, info, **args):
resolved = getattr(root, source, None)
resolved = default_resolver(source, None, root, info, **args)
if inspect.isfunction(resolved) or inspect.ismethod(resolved):
return resolved()
return resolved
Expand Down
7 changes: 7 additions & 0 deletions graphene/types/tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def test_field_source():
assert field.resolver(MyInstance(), None) == MyInstance.value


def test_field_source_dict_or_attr():
MyType = object()
field = Field(MyType, source="value")
assert field.resolver(MyInstance(), None) == MyInstance.value
assert field.resolver({"value": MyInstance.value}, None) == MyInstance.value


def test_field_with_lazy_type():
MyType = object()
field = Field(lambda: MyType)
Expand Down

0 comments on commit cb3bfe0

Please sign in to comment.