Skip to content

Commit 94e2a5c

Browse files
authored
Merge pull request #313 from BossGrand/feature/allow_abstract_connections
Allow DjangoObjectType to use an Abstract Connection Class
2 parents e666d84 + 2a39f5d commit 94e2a5c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

graphene_django/tests/test_types.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from mock import patch
22

3-
from graphene import Interface, ObjectType, Schema
3+
from graphene import Interface, ObjectType, Schema, Connection, String
44
from graphene.relay import Node
55

66
from .. import registry
@@ -17,11 +17,23 @@ class Meta:
1717
model = ReporterModel
1818

1919

20+
class ArticleConnection(Connection):
21+
'''Article Connection'''
22+
test = String()
23+
24+
def resolve_test():
25+
return 'test'
26+
27+
class Meta:
28+
abstract = True
29+
30+
2031
class Article(DjangoObjectType):
2132
'''Article description'''
2233
class Meta:
2334
model = ArticleModel
2435
interfaces = (Node, )
36+
connection_class = ArticleConnection
2537

2638

2739
class RootQuery(ObjectType):
@@ -74,6 +86,7 @@ def test_schema_representation():
7486
type ArticleConnection {
7587
pageInfo: PageInfo!
7688
edges: [ArticleEdge]!
89+
test: String
7790
}
7891
7992
type ArticleEdge {

graphene_django/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DjangoObjectType(ObjectType):
4545
@classmethod
4646
def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False,
4747
only_fields=(), exclude_fields=(), filter_fields=None, connection=None,
48-
use_connection=None, interfaces=(), **options):
48+
connection_class=None, use_connection=None, interfaces=(), **options):
4949
assert is_valid_django_model(model), (
5050
'You need to pass a valid Django Model in {}.Meta, received "{}".'
5151
).format(cls.__name__, model)
@@ -71,7 +71,11 @@ def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=Fa
7171

7272
if use_connection and not connection:
7373
# We create the connection automatically
74-
connection = Connection.create_type('{}Connection'.format(cls.__name__), node=cls)
74+
if not connection_class:
75+
connection_class = Connection
76+
77+
connection = connection_class.create_type(
78+
'{}Connection'.format(cls.__name__), node=cls)
7579

7680
if connection is not None:
7781
assert issubclass(connection, Connection), (

0 commit comments

Comments
 (0)