Skip to content

Commit e5bdaec

Browse files
committed
Create SQLAlchemyConnectionField through a factory method. Overriding the contructor-method gives the user the possibility to enhance the standard implementation
1 parent ceb5cc5 commit e5bdaec

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from graphene.relay import is_node
99
from graphene.types.json import JSONString
1010

11-
from .fields import SQLAlchemyConnectionField
11+
from .fields import createConnectionField
1212

1313
try:
1414
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
@@ -36,7 +36,7 @@ def dynamic_type():
3636
elif (direction == interfaces.ONETOMANY or
3737
direction == interfaces.MANYTOMANY):
3838
if is_node(_type):
39-
return SQLAlchemyConnectionField(_type)
39+
return createConnectionField(_type)
4040
return Field(List(_type))
4141

4242
return Dynamic(dynamic_type)

graphene_sqlalchemy/fields.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i
4141

4242
def get_resolver(self, parent_resolver):
4343
return partial(self.connection_resolver, parent_resolver, self.type, self.model)
44+
45+
__connectionFactory = SQLAlchemyConnectionField
46+
def createConnectionField(_type):
47+
return __connectionFactory(_type)
48+
49+
def registerConnectionFieldFactory(factoryMethod):
50+
global __connectionFactory
51+
__connectionFactory = factoryMethod

0 commit comments

Comments
 (0)