Skip to content

Commit 11dbde3

Browse files
tcleonardThomas Leonard
andauthored
Fix Connection/Edge naming and add unit test (#1012)
Co-authored-by: Thomas Leonard <[email protected]>
1 parent 55769e8 commit 11dbde3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

graphene_django/tests/test_types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from graphene.relay import Node
1010

1111
from .. import registry
12+
from ..filter import DjangoFilterConnectionField
1213
from ..types import DjangoObjectType, DjangoObjectTypeOptions
1314
from .models import Article as ArticleModel
1415
from .models import Reporter as ReporterModel
@@ -580,3 +581,28 @@ class Query(ObjectType):
580581
}
581582
"""
582583
)
584+
585+
586+
@with_local_registry
587+
def test_django_objecttype_name_connection_propagation():
588+
class Reporter(DjangoObjectType):
589+
class Meta:
590+
model = ReporterModel
591+
name = "CustomReporterName"
592+
filter_fields = ["email"]
593+
interfaces = (Node,)
594+
595+
class Query(ObjectType):
596+
reporter = Node.Field(Reporter)
597+
reporters = DjangoFilterConnectionField(Reporter)
598+
599+
assert Reporter._meta.name == "CustomReporterName"
600+
schema = str(Schema(query=Query))
601+
602+
assert "type CustomReporterName implements Node {" in schema
603+
assert "type CustomReporterNameConnection {" in schema
604+
assert "type CustomReporterNameEdge {" in schema
605+
606+
assert "type Reporter implements Node {" not in schema
607+
assert "type ReporterConnection {" not in schema
608+
assert "type ReporterEdge {" not in schema

graphene_django/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def __init_subclass_with_meta__(
239239
connection_class = Connection
240240

241241
connection = connection_class.create_type(
242-
"{}Connection".format(cls.__name__), node=cls
242+
"{}Connection".format(options.get("name") or cls.__name__), node=cls
243243
)
244244

245245
if connection is not None:

0 commit comments

Comments
 (0)