mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-14 05:36:45 +03:00
Improved abstract type
This commit is contained in:
parent
8bac3dc9e5
commit
85d3145862
|
@ -1,9 +1,12 @@
|
||||||
from ..pyutils.init_subclass import InitSubclassMeta
|
from ..utils.subclass_with_meta import SubclassWithMeta
|
||||||
|
from ..utils.deprecated import warn_deprecation
|
||||||
|
|
||||||
|
|
||||||
class AbstractType(object):
|
class AbstractType(SubclassWithMeta):
|
||||||
__metaclass__ = InitSubclassMeta
|
|
||||||
|
|
||||||
def __init_subclass__(cls, *args, **kwargs):
|
def __init_subclass__(cls, *args, **kwargs):
|
||||||
print("Abstract type is deprecated")
|
warn_deprecation(
|
||||||
# super(AbstractType, cls).__init_subclass__(*args, **kwargs)
|
"Abstract type is deprecated, please use normal object inheritance instead.\n"
|
||||||
|
"See more: https://github.com/graphql-python/graphene/blob/2.0/UPGRADE-v2.0.md#deprecations"
|
||||||
|
)
|
||||||
|
super(AbstractType, cls).__init_subclass__(*args, **kwargs)
|
||||||
|
|
40
graphene/types/tests/test_abstracttype.py
Normal file
40
graphene/types/tests/test_abstracttype.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ..objecttype import ObjectType
|
||||||
|
from ..unmountedtype import UnmountedType
|
||||||
|
from ..abstracttype import AbstractType
|
||||||
|
from ..field import Field
|
||||||
|
from ...utils import deprecated
|
||||||
|
|
||||||
|
|
||||||
|
class MyType(ObjectType):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MyScalar(UnmountedType):
|
||||||
|
|
||||||
|
def get_type(self):
|
||||||
|
return MyType
|
||||||
|
|
||||||
|
|
||||||
|
def test_abstract_objecttype_warn_deprecation(mocker):
|
||||||
|
mocker.patch.object(deprecated, 'warn_deprecation')
|
||||||
|
|
||||||
|
class MyAbstractType(AbstractType):
|
||||||
|
field1 = MyScalar()
|
||||||
|
|
||||||
|
deprecated.warn_deprecation.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_objecttype_inherit_abstracttype():
|
||||||
|
class MyAbstractType(AbstractType):
|
||||||
|
field1 = MyScalar()
|
||||||
|
|
||||||
|
class MyObjectType(ObjectType, MyAbstractType):
|
||||||
|
field2 = MyScalar()
|
||||||
|
|
||||||
|
assert MyObjectType._meta.description is None
|
||||||
|
assert MyObjectType._meta.interfaces == ()
|
||||||
|
assert MyObjectType._meta.name == "MyObjectType"
|
||||||
|
assert list(MyObjectType._meta.fields.keys()) == ['field1', 'field2']
|
||||||
|
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]
|
Loading…
Reference in New Issue
Block a user