mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Use default_resolver to resolve values when using the source at… (#1155)
This commit is contained in:
parent
6f2863ef6e
commit
cb3bfe011f
|
@ -4,6 +4,7 @@ from functools import partial
|
||||||
|
|
||||||
from .argument import Argument, to_arguments
|
from .argument import Argument, to_arguments
|
||||||
from .mountedtype import MountedType
|
from .mountedtype import MountedType
|
||||||
|
from .resolver import default_resolver
|
||||||
from .structures import NonNull
|
from .structures import NonNull
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
from .utils import get_type
|
from .utils import get_type
|
||||||
|
@ -12,7 +13,7 @@ base_type = type
|
||||||
|
|
||||||
|
|
||||||
def source_resolver(source, root, info, **args):
|
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):
|
if inspect.isfunction(resolved) or inspect.ismethod(resolved):
|
||||||
return resolved()
|
return resolved()
|
||||||
return resolved
|
return resolved
|
||||||
|
|
|
@ -66,6 +66,13 @@ def test_field_source():
|
||||||
assert field.resolver(MyInstance(), None) == MyInstance.value
|
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():
|
def test_field_with_lazy_type():
|
||||||
MyType = object()
|
MyType = object()
|
||||||
field = Field(lambda: MyType)
|
field = Field(lambda: MyType)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user