diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 83d9b40..a69870d 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -4,7 +4,7 @@ from graphene import Interface, ObjectType, Schema, Connection, String from graphene.relay import Node from .. import registry -from ..types import DjangoObjectType +from ..types import DjangoObjectType, DjangoObjectTypeOptions from .models import Article as ArticleModel from .models import Reporter as ReporterModel @@ -67,6 +67,26 @@ def test_django_objecttype_with_node_have_correct_fields(): assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'editor', 'lang', 'importance'] +def test_django_objecttype_with_custom_meta(): + class ArticleTypeOptions(DjangoObjectTypeOptions): + '''Article Type Options''' + + class ArticleType(DjangoObjectType): + class Meta: + abstract = True + + @classmethod + def __init_subclass_with_meta__(cls, _meta=None, **options): + _meta = ArticleTypeOptions(cls) + super(ArticleType, cls).__init_subclass_with_meta__(_meta=_meta, **options) + + class Article(ArticleType): + class Meta: + model = ArticleModel + + assert isinstance(Article._meta, ArticleTypeOptions) + + def test_schema_representation(): expected = """ schema { diff --git a/graphene_django/types.py b/graphene_django/types.py index 684863a..54ed87b 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -45,7 +45,7 @@ class DjangoObjectType(ObjectType): @classmethod def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False, only_fields=(), exclude_fields=(), filter_fields=None, connection=None, - connection_class=None, use_connection=None, interfaces=(), **options): + connection_class=None, use_connection=None, interfaces=(), _meta=None, **options): assert is_valid_django_model(model), ( 'You need to pass a valid Django Model in {}.Meta, received "{}".' ).format(cls.__name__, model) @@ -82,7 +82,9 @@ class DjangoObjectType(ObjectType): "The connection must be a Connection. Received {}" ).format(connection.__name__) - _meta = DjangoObjectTypeOptions(cls) + if not _meta: + _meta = DjangoObjectTypeOptions(cls) + _meta.model = model _meta.registry = registry _meta.filter_fields = filter_fields