Fix Connection/Edge naming and add unit test

This commit is contained in:
Thomas Leonard 2020-07-28 09:19:14 +01:00
parent b552dcac24
commit f0ab360f8d
2 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,7 @@ from graphene.relay import Node
from .. import registry
from ..types import DjangoObjectType, DjangoObjectTypeOptions
from ..filter import DjangoFilterConnectionField
from .models import Article as ArticleModel
from .models import Reporter as ReporterModel
@ -580,3 +581,27 @@ class TestDjangoObjectType:
}
"""
)
@with_local_registry
def test_django_objecttype_name_connection_propagation():
class Reporter(DjangoObjectType):
class Meta:
model = ReporterModel
name = "CustomReporterName"
filter_fields = ["email"]
interfaces = (Node, )
class Query(ObjectType):
reporter = Node.Field(Reporter)
reporters = DjangoFilterConnectionField(Reporter)
assert Reporter._meta.name == "CustomReporterName"
schema = str(Schema(query=Query))
assert "type CustomReporterName implements Node {" in schema
assert "type CustomReporterNameConnection {" in schema
assert "type CustomReporterNameEdge {" in schema
assert "type Reporter implements Node {" not in schema
assert "type ReporterConnection {" not in schema
assert "type ReporterEdge {" not in schema

View File

@ -239,7 +239,7 @@ class DjangoObjectType(ObjectType):
connection_class = Connection
connection = connection_class.create_type(
"{}Connection".format(cls.__name__), node=cls
"{}Connection".format(options.get("name") or cls.__name__), node=cls
)
if connection is not None: