Repository: graphql-python/graphene
Pull request #630 (2017-12-17 05:50:43)

extended support for subclassing with meta to Enum and InputObjectType
Fixes https://github.com/graphql-python/graphene/issues/566


Patch:
diff --git a/graphene/types/enum.py b/graphene/types/enum.py
index 4e3f2ac..da0b624 100644
--- a/graphene/types/enum.py
+++ b/graphene/types/enum.py
@@ -60,8 +60,9 @@ class EnumMeta(SubclassWithMeta_Meta):
 class Enum(six.with_metaclass(EnumMeta, UnmountedType, BaseType)):
 
     @classmethod
-    def __init_subclass_with_meta__(cls, enum=None, **options):
-        _meta = EnumOptions(cls)
+    def __init_subclass_with_meta__(cls, enum=None, _meta=None, **options):
+        if not _meta:
+            _meta = EnumOptions(cls)
         _meta.enum = enum or cls.__enum__
         _meta.deprecation_reason = options.pop('deprecation_reason', None)
         for key, value in _meta.enum.__members__.items():
diff --git a/graphene/types/inputobjecttype.py b/graphene/types/inputobjecttype.py
index 76f5dd0..dbfccc4 100644
--- a/graphene/types/inputobjecttype.py
+++ b/graphene/types/inputobjecttype.py
@@ -40,8 +40,9 @@ class InputObjectType(UnmountedType, BaseType):
     '''
 
     @classmethod
-    def __init_subclass_with_meta__(cls, container=None, **options):
-        _meta = InputObjectTypeOptions(cls)
+    def __init_subclass_with_meta__(cls, container=None, _meta=None, **options):
+        if not _meta:
+            _meta = InputObjectTypeOptions(cls)
 
         fields = OrderedDict()
         for base in reversed(cls.__mro__):


Test patch:
diff --git a/graphene/tests/issues/test_425.py b/graphene/tests/issues/test_425.py
index 7f92a75..d50edf8 100644
--- a/graphene/tests/issues/test_425.py
+++ b/graphene/tests/issues/test_425.py
@@ -2,8 +2,11 @@
 # Adapted for Graphene 2.0
 
 from graphene.types.objecttype import ObjectType, ObjectTypeOptions
+from graphene.types.inputobjecttype import InputObjectType, InputObjectTypeOptions
+from graphene.types.enum import Enum, EnumOptions
 
 
+# ObjectType
 class SpecialOptions(ObjectTypeOptions):
     other_attr = None
 
@@ -40,3 +43,77 @@ def test_special_objecttype_inherit_meta_options():
     assert MyType._meta.name == 'MyType'
     assert MyType._meta.default_resolver is None
     assert MyType._meta.interfaces == ()
+
+
+# InputObjectType
+class SpecialInputObjectTypeOptions(ObjectTypeOptions):
+    other_attr = None
+
+
+class SpecialInputObjectType(InputObjectType):
+
+    @classmethod
+    def __init_subclass_with_meta__(cls, other_attr='default', **options):
+        _meta = SpecialInputObjectTypeOptions(cls)
+        _meta.other_attr = other_attr
+        super(SpecialInputObjectType, cls).__init_subclass_with_meta__(_meta=_meta, **options)
+
+
+def test_special_inputobjecttype_could_be_subclassed():
+    class MyInputObjectType(SpecialInputObjectType):
+
+        class Meta:
+            other_attr = 'yeah!'
+
+    assert MyInputObjectType._meta.other_attr == 'yeah!'
+
+
+def test_special_inputobjecttype_could_be_subclassed_default():
+    class MyInputObjectType(SpecialInputObjectType):
+        pass
+
+    assert MyInputObjectType._meta.other_attr == 'default'
+
+
+def test_special_inputobjecttype_inherit_meta_options():
+    class MyInputObjectType(SpecialInputObjectType):
+        pass
+
+    assert MyInputObjectType._meta.name == 'MyInputObjectType'
+
+
+# Enum
+class SpecialEnumOptions(EnumOptions):
+    other_attr = None
+
+
+class SpecialEnum(Enum):
+
+    @classmethod
+    def __init_subclass_with_meta__(cls, other_attr='default', **options):
+        _meta = SpecialEnumOptions(cls)
+        _meta.other_attr = other_attr
+        super(SpecialEnum, cls).__init_subclass_with_meta__(_meta=_meta, **options)
+
+
+def test_special_enum_could_be_subclassed():
+    class MyEnum(SpecialEnum):
+
+        class Meta:
+            other_attr = 'yeah!'
+
+    assert MyEnum._meta.other_attr == 'yeah!'
+
+
+def test_special_enum_could_be_subclassed_default():
+    class MyEnum(SpecialEnum):
+        pass
+
+    assert MyEnum._meta.other_attr == 'default'
+
+
+def test_special_enum_inherit_meta_options():
+    class MyEnum(SpecialEnum):
+        pass
+
+    assert MyEnum._meta.name == 'MyEnum'