mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-27 08:19:45 +03:00
Merge f3865300ff
into eb5108f81e
This commit is contained in:
commit
f9b071d724
|
@ -4,6 +4,8 @@ from .unmountedtype import UnmountedType
|
|||
|
||||
class MountedType(OrderedType):
|
||||
|
||||
_mount_cls_override = None
|
||||
|
||||
@classmethod
|
||||
def mounted(cls, unmounted): # noqa: N802
|
||||
'''
|
||||
|
@ -13,7 +15,9 @@ class MountedType(OrderedType):
|
|||
'{} can\'t mount {}'
|
||||
).format(cls.__name__, repr(unmounted))
|
||||
|
||||
return cls(
|
||||
mount_cls = cls._mount_cls_override or cls
|
||||
|
||||
return mount_cls(
|
||||
unmounted.get_type(),
|
||||
*unmounted.args,
|
||||
_creation_counter=unmounted.creation_counter,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
from ..field import Field
|
||||
from ..objecttype import ObjectType
|
||||
from ..scalars import String
|
||||
|
||||
|
||||
|
@ -23,3 +24,36 @@ def test_mounted_type_custom():
|
|||
assert isinstance(mounted, CustomField)
|
||||
assert mounted.type == String
|
||||
assert mounted.metadata == {'hey': 'yo!'}
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def custom_field():
|
||||
# We set the override
|
||||
Field._mount_cls_override = CustomField
|
||||
|
||||
# Run the test
|
||||
yield CustomField
|
||||
|
||||
# Remove the class override (back to the original state)
|
||||
Field._mount_cls_override = None
|
||||
|
||||
|
||||
def test_mounted_type_overrided(custom_field):
|
||||
# This function is using the custom_field yield fixture
|
||||
|
||||
unmounted = String(metadata={'hey': 'yo!'})
|
||||
mounted = Field.mount(unmounted)
|
||||
assert isinstance(mounted, CustomField)
|
||||
assert mounted.type == String
|
||||
assert mounted.metadata == {'hey': 'yo!'}
|
||||
|
||||
|
||||
def test_mounted_type_overrided(custom_field):
|
||||
# This function is using the custom_field yield fixture
|
||||
|
||||
class Query(ObjectType):
|
||||
test = String(metadata={'other': 'thing'})
|
||||
|
||||
test_field = Query._meta.fields['test']
|
||||
assert isinstance(test_field, CustomField)
|
||||
assert test_field.metadata == {'other': 'thing'}
|
||||
|
|
Loading…
Reference in New Issue
Block a user