From e5bdaecc5fe5a1263958fe6f05b3f50cd3ad0318 Mon Sep 17 00:00:00 2001 From: Palm Kevin Date: Mon, 21 Nov 2016 08:27:02 +0100 Subject: [PATCH 1/2] Create SQLAlchemyConnectionField through a factory method. Overriding the contructor-method gives the user the possibility to enhance the standard implementation --- graphene_sqlalchemy/converter.py | 4 ++-- graphene_sqlalchemy/fields.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 05690697..9b110cfb 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -8,7 +8,7 @@ from graphene.relay import is_node from graphene.types.json import JSONString -from .fields import SQLAlchemyConnectionField +from .fields import createConnectionField try: from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType @@ -36,7 +36,7 @@ def dynamic_type(): elif (direction == interfaces.ONETOMANY or direction == interfaces.MANYTOMANY): if is_node(_type): - return SQLAlchemyConnectionField(_type) + return createConnectionField(_type) return Field(List(_type)) return Dynamic(dynamic_type) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index de1d301f..0702a022 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -41,3 +41,11 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i def get_resolver(self, parent_resolver): return partial(self.connection_resolver, parent_resolver, self.type, self.model) + +__connectionFactory = SQLAlchemyConnectionField +def createConnectionField(_type): + return __connectionFactory(_type) + +def registerConnectionFieldFactory(factoryMethod): + global __connectionFactory + __connectionFactory = factoryMethod \ No newline at end of file From cbf0a2289fdb8edf51466f42e8600dcbddf9e53f Mon Sep 17 00:00:00 2001 From: Palm Kevin Date: Mon, 21 Nov 2016 08:41:47 +0100 Subject: [PATCH 2/2] Add free lins to match code lint checks --- graphene_sqlalchemy/fields.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 0702a022..31c73a5f 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -42,10 +42,14 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i def get_resolver(self, parent_resolver): return partial(self.connection_resolver, parent_resolver, self.type, self.model) + __connectionFactory = SQLAlchemyConnectionField + + def createConnectionField(_type): return __connectionFactory(_type) + def registerConnectionFieldFactory(factoryMethod): global __connectionFactory - __connectionFactory = factoryMethod \ No newline at end of file + __connectionFactory = factoryMethod