Skip to content

Commit

Permalink
Fix Connection/Edge naming and add unit test (#1012)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
  • Loading branch information
tcleonard and Thomas Leonard committed Aug 7, 2020
1 parent 55769e8 commit 11dbde3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions graphene_django/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from graphene.relay import Node

from .. import registry
from ..filter import DjangoFilterConnectionField
from ..types import DjangoObjectType, DjangoObjectTypeOptions
from .models import Article as ArticleModel
from .models import Reporter as ReporterModel
Expand Down Expand Up @@ -580,3 +581,28 @@ class Query(ObjectType):
}
"""
)


@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
2 changes: 1 addition & 1 deletion graphene_django/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init_subclass_with_meta__(
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:
Expand Down

0 comments on commit 11dbde3

Please sign in to comment.