From f29fe5c8fd4bc297c5559c5199bc52c21fdb2b08 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 21 Jan 2016 12:34:42 -0800 Subject: [PATCH] Fixed inheritance from abstract types. Fixed #84 --- graphene/core/classtypes/objecttype.py | 2 +- .../core/classtypes/tests/test_objecttype.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/graphene/core/classtypes/objecttype.py b/graphene/core/classtypes/objecttype.py index 32294d4e..442d78f5 100644 --- a/graphene/core/classtypes/objecttype.py +++ b/graphene/core/classtypes/objecttype.py @@ -12,7 +12,7 @@ from .uniontype import UnionType def is_objecttype(cls): if not issubclass(cls, ObjectType): return False - return not cls._meta.interface + return not(cls._meta.abstract or cls._meta.interface) class ObjectTypeOptions(FieldsOptions): diff --git a/graphene/core/classtypes/tests/test_objecttype.py b/graphene/core/classtypes/tests/test_objecttype.py index 93cabc76..5e71ab73 100644 --- a/graphene/core/classtypes/tests/test_objecttype.py +++ b/graphene/core/classtypes/tests/test_objecttype.py @@ -87,3 +87,30 @@ def test_object_type_union(): assert Thing._meta.type_name == 'Thing' assert Thing._meta.description == 'Thing union description' assert Thing.my_attr + + +def test_object_type_not_union_if_abstract(): + schema = Schema() + + class Query1(ObjectType): + field1 = String() + + class Meta: + abstract = True + + class Query2(ObjectType): + field2 = String() + + class Meta: + abstract = True + + class Query(Query1, Query2): + '''Query description''' + my_attr = True + + object_type = schema.T(Query) + assert issubclass(Query, ObjectType) + assert Query._meta.type_name == 'Query' + assert Query._meta.description == 'Query description' + assert isinstance(object_type, GraphQLObjectType) + assert list(Query._meta.fields_map.keys()) == ['field1', 'field2']