From eb625bb41ad24f806467fcc799357d6063d861fa Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Fri, 22 Mar 2019 09:01:04 -0400 Subject: [PATCH 1/6] tests pass test pass --- .gitignore | 1 + graphene_sqlalchemy/converter.py | 4 +- graphene_sqlalchemy/fields.py | 46 ++++++-- .../tests/test_connectionfactory.py | 109 +++++++++++------- setup.py | 10 ++ 5 files changed, 120 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index 2c4ca2b1..e4070f31 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ htmlcov/ nosetests.xml coverage.xml *,cover +.pytest_cache/ # Translations *.mo diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 053aa8b5..b30a6563 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -7,7 +7,7 @@ String) from graphene.types.json import JSONString -from .fields import createConnectionField +from .fields import create_connection_field try: from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType @@ -35,7 +35,7 @@ def dynamic_type(): return Field(_type) elif direction in (interfaces.ONETOMANY, interfaces.MANYTOMANY): if _type._meta.connection: - return createConnectionField(_type._meta.connection) + return create_connection_field(relationship, registry) return Field(List(_type)) return Dynamic(dynamic_type) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 7e313625..608eaab8 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -1,3 +1,4 @@ +import logging from functools import partial from promise import Promise, is_thenable @@ -10,6 +11,9 @@ from .utils import get_query, sort_argument_for_model +log = logging.getLogger() + + class UnsortedSQLAlchemyConnectionField(ConnectionField): @property def type(self): @@ -95,18 +99,46 @@ def __init__(self, type, *args, **kwargs): super(SQLAlchemyConnectionField, self).__init__(type, *args, **kwargs) -__connectionFactory = UnsortedSQLAlchemyConnectionField +def default_connection_field_factory(relationship, registry): + model = relationship.mapper.entity + _type = registry.get_type_for_model(model) + return UnsortedSQLAlchemyConnectionField(_type._meta.connection) + + +__connection_field_factory = default_connection_field_factory +def create_connection_field(relationship, registry): + return __connection_field_factory(relationship, registry) -def createConnectionField(_type): - return __connectionFactory(_type) +def register_connection_field_factory(connection_factory): + global __connection_field_factory + __connection_field_factory = connection_factory +def unregister_connection_field_factory(): + global __connection_field_factory + __connection_field_factory = default_connection_field_factory + + +# TODO Remove in next major version def registerConnectionFieldFactory(factoryMethod): - global __connectionFactory - __connectionFactory = factoryMethod + log.warn( + 'registerConnectionFieldFactory is deprecated and will be removed in the next ' + 'major version. Use register_connection_field_factory instead.' + ) + + def old_factory_method_wrapper(relationship, registry): + model = relationship.mapper.entity + _type = registry.get_type_for_model(model) + return factoryMethod(_type) + + register_connection_field_factory(old_factory_method_wrapper) def unregisterConnectionFieldFactory(): - global __connectionFactory - __connectionFactory = UnsortedSQLAlchemyConnectionField + log.warn( + 'registerConnectionFieldFactory is deprecated and will be removed in the next ' + 'major version. Use unregister_connection_field_factory instead.' + ) + + unregister_connection_field_factory() diff --git a/graphene_sqlalchemy/tests/test_connectionfactory.py b/graphene_sqlalchemy/tests/test_connectionfactory.py index 796be5a4..0eaedc75 100644 --- a/graphene_sqlalchemy/tests/test_connectionfactory.py +++ b/graphene_sqlalchemy/tests/test_connectionfactory.py @@ -1,42 +1,69 @@ -import graphene -from graphene_sqlalchemy.fields import (SQLAlchemyConnectionField, - registerConnectionFieldFactory, - unregisterConnectionFieldFactory) - - -def test_register(): - class LXConnectionField(SQLAlchemyConnectionField): - @classmethod - def _applyQueryArgs(cls, model, q, args): - return q - - @classmethod - def connection_resolver( - cls, resolver, connection, model, root, args, context, info - ): - def LXResolver(root, args, context, info): - iterable = resolver(root, args, context, info) - if iterable is None: - iterable = cls.get_query(model, context, info, args) - - # We accept always a query here. All LX-queries can be filtered and sorted - iterable = cls._applyQueryArgs(model, iterable, args) - return iterable - - return SQLAlchemyConnectionField.connection_resolver( - LXResolver, connection, model, root, args, context, info - ) - - def createLXConnectionField(table): - class LXConnection(graphene.relay.Connection): - class Meta: - node = table - - return LXConnectionField( - LXConnection, - filter=table.filter(), - order_by=graphene.List(of_type=table.order_by), - ) - - registerConnectionFieldFactory(createLXConnectionField) +from graphene_sqlalchemy.fields import ( + SQLAlchemyConnectionField, + register_connection_field_factory, + unregister_connection_field_factory, + registerConnectionFieldFactory, + unregisterConnectionFieldFactory, +) +from graphene_sqlalchemy.types import SQLAlchemyObjectType +from graphene_sqlalchemy.tests.models import Article, Reporter +from graphene_sqlalchemy.registry import Registry +from graphene import Connection, Node + + +def define_types(): + _registry = Registry() + + class ReporterType(SQLAlchemyObjectType): + class Meta: + model = Reporter + registry = _registry + interfaces = (Node,) + + + class ArticleType(SQLAlchemyObjectType): + class Meta: + model = Article + registry = _registry + interfaces = (Node,) + + return { + 'ReporterType': ReporterType, + 'ArticleType': ArticleType, + } + + +def test_register_connection_field_factory(): + def connection_field_factory(relationship, registry): + model = relationship.mapper.entity + _type = registry.get_type_for_model(model) + return SQLAlchemyConnectionField(_type._meta.connection) + + register_connection_field_factory(connection_field_factory) + + types = define_types() + + assert isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) + + +def test_unregister_connection_field_factory(): + register_connection_field_factory(lambda: None) + unregister_connection_field_factory() + + types = define_types() + + assert not isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) + + +def test_deprecated_registerConnectionFieldFactory(): + registerConnectionFieldFactory(SQLAlchemyConnectionField) + types = define_types() + assert isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) + + +def test_deprecated_unregisterConnectionFieldFactory(): + registerConnectionFieldFactory(SQLAlchemyConnectionField) unregisterConnectionFieldFactory() + types = define_types() + + assert not isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) diff --git a/setup.py b/setup.py index 66704b28..e72c1eaa 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,7 @@ ], keywords="api graphql protocol rest relay graphene", packages=find_packages(exclude=["tests"]), +<<<<<<< HEAD install_requires=requirements, extras_require={ "dev": [ @@ -66,4 +67,13 @@ "test": tests_require, }, tests_require=tests_require, +======= + install_requires=[ + "six>=1.10.0", + "graphene>=2.1.3", + "SQLAlchemy", + "singledispatch>=3.4.0.3", + ], + tests_require=["pytest>=2.7.2", "mock", "sqlalchemy_utils", "enum34"], +>>>>>>> tests pass ) From b9bd42d0141f268d955c64f56db41fcc8bd65fce Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Mon, 25 Mar 2019 15:53:35 -0400 Subject: [PATCH 2/6] remove enum34 --- setup.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/setup.py b/setup.py index e72c1eaa..66704b28 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ ], keywords="api graphql protocol rest relay graphene", packages=find_packages(exclude=["tests"]), -<<<<<<< HEAD install_requires=requirements, extras_require={ "dev": [ @@ -67,13 +66,4 @@ "test": tests_require, }, tests_require=tests_require, -======= - install_requires=[ - "six>=1.10.0", - "graphene>=2.1.3", - "SQLAlchemy", - "singledispatch>=3.4.0.3", - ], - tests_require=["pytest>=2.7.2", "mock", "sqlalchemy_utils", "enum34"], ->>>>>>> tests pass ) From dc7e2bbefeee336cd043355bc253fe92314aed29 Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Tue, 2 Apr 2019 14:34:39 -0400 Subject: [PATCH 3/6] rebase, move to meta and address comments --- graphene_sqlalchemy/converter.py | 6 +- graphene_sqlalchemy/fields.py | 58 +++++------ .../tests/test_connectionfactory.py | 69 ------------- graphene_sqlalchemy/tests/test_types.py | 98 ++++++++++++++++++- graphene_sqlalchemy/types.py | 15 ++- 5 files changed, 135 insertions(+), 111 deletions(-) delete mode 100644 graphene_sqlalchemy/tests/test_connectionfactory.py diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index b30a6563..7cc259e0 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -7,8 +7,6 @@ String) from graphene.types.json import JSONString -from .fields import create_connection_field - try: from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType except ImportError: @@ -23,7 +21,7 @@ def is_column_nullable(column): return bool(getattr(column, "nullable", True)) -def convert_sqlalchemy_relationship(relationship, registry): +def convert_sqlalchemy_relationship(relationship, registry, connection_field_factory): direction = relationship.direction model = relationship.mapper.entity @@ -35,7 +33,7 @@ def dynamic_type(): return Field(_type) elif direction in (interfaces.ONETOMANY, interfaces.MANYTOMANY): if _type._meta.connection: - return create_connection_field(relationship, registry) + return connection_field_factory(relationship, registry) return Field(List(_type)) return Dynamic(dynamic_type) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 608eaab8..cc426aa5 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -10,7 +10,6 @@ from .utils import get_query, sort_argument_for_model - log = logging.getLogger() @@ -99,46 +98,41 @@ def __init__(self, type, *args, **kwargs): super(SQLAlchemyConnectionField, self).__init__(type, *args, **kwargs) -def default_connection_field_factory(relationship, registry): - model = relationship.mapper.entity - _type = registry.get_type_for_model(model) - return UnsortedSQLAlchemyConnectionField(_type._meta.connection) - - -__connection_field_factory = default_connection_field_factory - -def create_connection_field(relationship, registry): - return __connection_field_factory(relationship, registry) +# TODO Remove in next major version +__connectionFactory = UnsortedSQLAlchemyConnectionField -def register_connection_field_factory(connection_factory): - global __connection_field_factory - __connection_field_factory = connection_factory -def unregister_connection_field_factory(): - global __connection_field_factory - __connection_field_factory = default_connection_field_factory +def createConnectionField(_type): + log.warn( + 'createConnectionField is deprecated and will be removed in the next ' + 'major version. Use TODO instead.' + ) + return __connectionFactory(_type) -# TODO Remove in next major version - def registerConnectionFieldFactory(factoryMethod): log.warn( 'registerConnectionFieldFactory is deprecated and will be removed in the next ' - 'major version. Use register_connection_field_factory instead.' - ) - - def old_factory_method_wrapper(relationship, registry): - model = relationship.mapper.entity - _type = registry.get_type_for_model(model) - return factoryMethod(_type) - - register_connection_field_factory(old_factory_method_wrapper) + 'major version. Use TODO instead.' + ) + global __connectionFactory + __connectionFactory = factoryMethod def unregisterConnectionFieldFactory(): log.warn( 'registerConnectionFieldFactory is deprecated and will be removed in the next ' - 'major version. Use unregister_connection_field_factory instead.' - ) - - unregister_connection_field_factory() + 'major version. Use TODO instead.' + ) + global __connectionFactory + __connectionFactory = UnsortedSQLAlchemyConnectionField + + +def default_connection_field_factory(relationship, registry): + log.warn( + 'This is deprecated and will be removed in the next ' + 'major version. Use TODO instead.' + ) + model = relationship.mapper.entity + model_type = registry.get_type_for_model(model) + return createConnectionField(model_type) diff --git a/graphene_sqlalchemy/tests/test_connectionfactory.py b/graphene_sqlalchemy/tests/test_connectionfactory.py deleted file mode 100644 index 0eaedc75..00000000 --- a/graphene_sqlalchemy/tests/test_connectionfactory.py +++ /dev/null @@ -1,69 +0,0 @@ -from graphene_sqlalchemy.fields import ( - SQLAlchemyConnectionField, - register_connection_field_factory, - unregister_connection_field_factory, - registerConnectionFieldFactory, - unregisterConnectionFieldFactory, -) -from graphene_sqlalchemy.types import SQLAlchemyObjectType -from graphene_sqlalchemy.tests.models import Article, Reporter -from graphene_sqlalchemy.registry import Registry -from graphene import Connection, Node - - -def define_types(): - _registry = Registry() - - class ReporterType(SQLAlchemyObjectType): - class Meta: - model = Reporter - registry = _registry - interfaces = (Node,) - - - class ArticleType(SQLAlchemyObjectType): - class Meta: - model = Article - registry = _registry - interfaces = (Node,) - - return { - 'ReporterType': ReporterType, - 'ArticleType': ArticleType, - } - - -def test_register_connection_field_factory(): - def connection_field_factory(relationship, registry): - model = relationship.mapper.entity - _type = registry.get_type_for_model(model) - return SQLAlchemyConnectionField(_type._meta.connection) - - register_connection_field_factory(connection_field_factory) - - types = define_types() - - assert isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) - - -def test_unregister_connection_field_factory(): - register_connection_field_factory(lambda: None) - unregister_connection_field_factory() - - types = define_types() - - assert not isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) - - -def test_deprecated_registerConnectionFieldFactory(): - registerConnectionFieldFactory(SQLAlchemyConnectionField) - types = define_types() - assert isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) - - -def test_deprecated_unregisterConnectionFieldFactory(): - registerConnectionFieldFactory(SQLAlchemyConnectionField) - unregisterConnectionFieldFactory() - types = define_types() - - assert not isinstance(types['ReporterType']._meta.fields['articles'].type(), SQLAlchemyConnectionField) diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index 5eaf0137..0360a644 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -3,10 +3,13 @@ import six # noqa F401 from promise import Promise -from graphene import Field, Int, Interface, ObjectType -from graphene.relay import Connection, Node, is_node +from graphene import (Connection, Field, Int, Interface, Node, ObjectType, + is_node) -from ..fields import SQLAlchemyConnectionField +from ..fields import (SQLAlchemyConnectionField, + UnsortedSQLAlchemyConnectionField, + registerConnectionFieldFactory, + unregisterConnectionFieldFactory) from ..registry import Registry from ..types import SQLAlchemyObjectType, SQLAlchemyObjectTypeOptions from .models import Article, Reporter @@ -185,3 +188,92 @@ def resolver(*args, **kwargs): resolver, TestConnection, ReporterWithCustomOptions, None, None ) assert result is not None + + +# Tests for connection_field_factory + +class _TestSQLAlchemyConnectionField(SQLAlchemyConnectionField): + pass + + +def test_default_connection_field_factory(): + _registry = Registry() + + class ReporterType(SQLAlchemyObjectType): + class Meta: + model = Reporter + registry = _registry + interfaces = (Node,) + + class ArticleType(SQLAlchemyObjectType): + class Meta: + model = Article + registry = _registry + interfaces = (Node,) + + assert isinstance(ReporterType._meta.fields['articles'].type(), UnsortedSQLAlchemyConnectionField) + + +def test_register_connection_field_factory(): + def test_connection_field_factory(relationship, registry): + model = relationship.mapper.entity + _type = registry.get_type_for_model(model) + return _TestSQLAlchemyConnectionField(_type._meta.connection) + + _registry = Registry() + + class ReporterType(SQLAlchemyObjectType): + class Meta: + model = Reporter + registry = _registry + interfaces = (Node,) + connection_field_factory = test_connection_field_factory + + class ArticleType(SQLAlchemyObjectType): + class Meta: + model = Article + registry = _registry + interfaces = (Node,) + + assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) + + +def test_deprecated_registerConnectionFieldFactory(): + registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) + + _registry = Registry() + + class ReporterType(SQLAlchemyObjectType): + class Meta: + model = Reporter + registry = _registry + interfaces = (Node,) + + class ArticleType(SQLAlchemyObjectType): + class Meta: + model = Article + registry = _registry + interfaces = (Node,) + + assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) + + +def test_deprecated_unregisterConnectionFieldFactory(): + registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) + unregisterConnectionFieldFactory() + + _registry = Registry() + + class ReporterType(SQLAlchemyObjectType): + class Meta: + model = Reporter + registry = _registry + interfaces = (Node,) + + class ArticleType(SQLAlchemyObjectType): + class Meta: + model = Article + registry = _registry + interfaces = (Node,) + + assert not isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index dde746ec..394d5062 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -14,11 +14,12 @@ convert_sqlalchemy_composite, convert_sqlalchemy_hybrid_method, convert_sqlalchemy_relationship) +from .fields import default_connection_field_factory from .registry import Registry, get_global_registry from .utils import get_query, is_mapped_class, is_mapped_instance -def construct_fields(model, registry, only_fields, exclude_fields): +def construct_fields(model, registry, only_fields, exclude_fields, connection_field_factory): inspected_model = sqlalchemyinspect(model) fields = OrderedDict() @@ -71,7 +72,7 @@ def construct_fields(model, registry, only_fields, exclude_fields): # We skip this field if we specify only_fields and is not # in there. Or when we exclude this field in exclude_fields continue - converted_relationship = convert_sqlalchemy_relationship(relationship, registry) + converted_relationship = convert_sqlalchemy_relationship(relationship, registry, connection_field_factory) name = relationship.key fields[name] = converted_relationship @@ -99,6 +100,7 @@ def __init_subclass_with_meta__( use_connection=None, interfaces=(), id=None, + connection_field_factory=default_connection_field_factory, _meta=None, **options ): @@ -115,7 +117,14 @@ def __init_subclass_with_meta__( ).format(cls.__name__, registry) sqla_fields = yank_fields_from_attrs( - construct_fields(model, registry, only_fields, exclude_fields), _as=Field + construct_fields( + model=model, + registry=registry, + only_fields=only_fields, + exclude_fields=exclude_fields, + connection_field_factory=connection_field_factory + ), + _as=Field ) if use_connection is None and interfaces: From 76613a7420e26d5e5373d323bbb01b42feb723c0 Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Tue, 2 Apr 2019 15:33:50 -0400 Subject: [PATCH 4/6] fix tests --- graphene_sqlalchemy/fields.py | 20 ++++++++++---------- graphene_sqlalchemy/tests/test_converter.py | 21 +++++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index cc426aa5..80be4461 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -98,6 +98,16 @@ def __init__(self, type, *args, **kwargs): super(SQLAlchemyConnectionField, self).__init__(type, *args, **kwargs) +def default_connection_field_factory(relationship, registry): + log.warn( + 'This is deprecated and will be removed in the next ' + 'major version. Use TODO instead.' + ) + model = relationship.mapper.entity + model_type = registry.get_type_for_model(model) + return createConnectionField(model_type) + + # TODO Remove in next major version __connectionFactory = UnsortedSQLAlchemyConnectionField @@ -126,13 +136,3 @@ def unregisterConnectionFieldFactory(): ) global __connectionFactory __connectionFactory = UnsortedSQLAlchemyConnectionField - - -def default_connection_field_factory(relationship, registry): - log.warn( - 'This is deprecated and will be removed in the next ' - 'major version. Use TODO instead.' - ) - model = relationship.mapper.entity - model_type = registry.get_type_for_model(model) - return createConnectionField(model_type) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index d205427b..2a4250ba 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -16,7 +16,8 @@ from ..converter import (convert_sqlalchemy_column, convert_sqlalchemy_composite, convert_sqlalchemy_relationship) -from ..fields import UnsortedSQLAlchemyConnectionField +from ..fields import (UnsortedSQLAlchemyConnectionField, + default_connection_field_factory) from ..registry import Registry from ..types import SQLAlchemyObjectType from .models import Article, Pet, Reporter @@ -179,7 +180,9 @@ def test_should_jsontype_convert_jsonstring(): def test_should_manytomany_convert_connectionorlist(): registry = Registry() - dynamic_field = convert_sqlalchemy_relationship(Reporter.pets.property, registry) + dynamic_field = convert_sqlalchemy_relationship( + Reporter.pets.property, registry, default_connection_field_factory + ) assert isinstance(dynamic_field, graphene.Dynamic) assert not dynamic_field.get_type() @@ -190,7 +193,7 @@ class Meta: model = Pet dynamic_field = convert_sqlalchemy_relationship( - Reporter.pets.property, A._meta.registry + Reporter.pets.property, A._meta.registry, test_should_manytomany_convert_connectionorlist ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() @@ -206,7 +209,7 @@ class Meta: interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( - Reporter.pets.property, A._meta.registry + Reporter.pets.property, A._meta.registry, default_connection_field_factory ) assert isinstance(dynamic_field, graphene.Dynamic) assert isinstance(dynamic_field.get_type(), UnsortedSQLAlchemyConnectionField) @@ -214,7 +217,9 @@ class Meta: def test_should_manytoone_convert_connectionorlist(): registry = Registry() - dynamic_field = convert_sqlalchemy_relationship(Article.reporter.property, registry) + dynamic_field = convert_sqlalchemy_relationship( + Article.reporter.property, registry, default_connection_field_factory + ) assert isinstance(dynamic_field, graphene.Dynamic) assert not dynamic_field.get_type() @@ -225,7 +230,7 @@ class Meta: model = Reporter dynamic_field = convert_sqlalchemy_relationship( - Article.reporter.property, A._meta.registry + Article.reporter.property, A._meta.registry, default_connection_field_factory ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() @@ -240,7 +245,7 @@ class Meta: interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( - Article.reporter.property, A._meta.registry + Article.reporter.property, A._meta.registry, default_connection_field_factory ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() @@ -255,7 +260,7 @@ class Meta: interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( - Reporter.favorite_article.property, A._meta.registry + Reporter.favorite_article.property, A._meta.registry, default_connection_field_factory ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() From 084f153f20145ea3ec729c9c8ce48a85147870e5 Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Tue, 2 Apr 2019 17:17:35 -0400 Subject: [PATCH 5/6] fix comments --- graphene_sqlalchemy/fields.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 80be4461..4a46b749 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -99,10 +99,6 @@ def __init__(self, type, *args, **kwargs): def default_connection_field_factory(relationship, registry): - log.warn( - 'This is deprecated and will be removed in the next ' - 'major version. Use TODO instead.' - ) model = relationship.mapper.entity model_type = registry.get_type_for_model(model) return createConnectionField(model_type) @@ -115,7 +111,7 @@ def default_connection_field_factory(relationship, registry): def createConnectionField(_type): log.warn( 'createConnectionField is deprecated and will be removed in the next ' - 'major version. Use TODO instead.' + 'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.' ) return __connectionFactory(_type) @@ -123,7 +119,7 @@ def createConnectionField(_type): def registerConnectionFieldFactory(factoryMethod): log.warn( 'registerConnectionFieldFactory is deprecated and will be removed in the next ' - 'major version. Use TODO instead.' + 'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.' ) global __connectionFactory __connectionFactory = factoryMethod @@ -132,7 +128,7 @@ def registerConnectionFieldFactory(factoryMethod): def unregisterConnectionFieldFactory(): log.warn( 'registerConnectionFieldFactory is deprecated and will be removed in the next ' - 'major version. Use TODO instead.' + 'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.' ) global __connectionFactory __connectionFactory = UnsortedSQLAlchemyConnectionField From b97bbfbd27317b2fa89126898f386459316bb359 Mon Sep 17 00:00:00 2001 From: Julien Nakache Date: Fri, 12 Apr 2019 16:16:08 -0400 Subject: [PATCH 6/6] fix test --- graphene_sqlalchemy/tests/test_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index 2a4250ba..5cc16e79 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -193,7 +193,7 @@ class Meta: model = Pet dynamic_field = convert_sqlalchemy_relationship( - Reporter.pets.property, A._meta.registry, test_should_manytomany_convert_connectionorlist + Reporter.pets.property, A._meta.registry, default_connection_field_factory ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type()