diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a62b5e1..a2c61a3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -20,15 +20,14 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - - name: Lint with flake8 - run: | - python -m pip install flake8 - flake8 graphene_mongo --count --show-source --statistics - name: Install dependencies run: | python -m pip install poetry poetry config virtualenvs.create false poetry install --with dev + - name: Lint + run: | + make lint - name: Run Tests run: make test - name: Build Package diff --git a/graphene_mongo/converter.py b/graphene_mongo/converter.py index 808a06b..7bed391 100644 --- a/graphene_mongo/converter.py +++ b/graphene_mongo/converter.py @@ -197,13 +197,15 @@ def reference_resolver(root, *args, **kwargs): if model in to_resolve_models: futures.append( pool.submit( - get_reference_objects, (model, object_id_list, registry, args) + get_reference_objects, + (model, object_id_list, registry, args), ) ) else: futures.append( pool.submit( - get_non_querying_object, (model, object_id_list, registry, args) + get_non_querying_object, + (model, object_id_list, registry, args), ) ) result = list() @@ -325,7 +327,9 @@ async def reference_resolver_async(root, *args, **kwargs): base_type = type(base_type) return graphene.List( - base_type, description=get_field_description(field, registry), required=field.required + base_type, + description=get_field_description(field, registry), + required=field.required, ) @@ -634,7 +638,9 @@ def dynamic_type(): return None if isinstance(field, mongoengine.EmbeddedDocumentField): return graphene.Field( - _type, description=get_field_description(field, registry), required=field.required + _type, + description=get_field_description(field, registry), + required=field.required, ) field_resolver = None required = False @@ -764,5 +770,7 @@ def convert_field_to_enum(field, registry=None, executor: ExecutorEnum = Executo registry.register_enum(field._enum_cls) _type = registry.get_type_for_enum(field._enum_cls) return graphene.Field( - _type, description=get_field_description(field, registry), required=field.required + _type, + description=get_field_description(field, registry), + required=field.required, ) diff --git a/graphene_mongo/fields.py b/graphene_mongo/fields.py index 1e6bdf0..f7a448f 100644 --- a/graphene_mongo/fields.py +++ b/graphene_mongo/fields.py @@ -296,7 +296,8 @@ def get_queryset( reference_obj = reference_fields[arg_name].document_type(pk=arg) hydrated_references[arg_name] = reference_obj elif arg_name in self.model._fields_ordered and isinstance( - getattr(self.model, arg_name), mongoengine.fields.GenericReferenceField + getattr(self.model, arg_name), + mongoengine.fields.GenericReferenceField, ): try: reference_obj = get_document( @@ -306,7 +307,8 @@ def get_queryset( reference_obj = get_document(arg["_cls"])(pk=arg["_ref"].id) hydrated_references[arg_name] = reference_obj elif "__near" in arg_name and isinstance( - getattr(self.model, arg_name.split("__")[0]), mongoengine.fields.PointField + getattr(self.model, arg_name.split("__")[0]), + mongoengine.fields.PointField, ): location = args.pop(arg_name, None) hydrated_references[arg_name] = location["coordinates"] @@ -383,7 +385,8 @@ def default_resolver(self, _root, info, required_fields=None, resolved=None, **a elif field_name in _root._fields_ordered and not ( isinstance(_root._fields[field_name].field, mongoengine.EmbeddedDocumentField) or isinstance( - _root._fields[field_name].field, mongoengine.GenericEmbeddedDocumentField + _root._fields[field_name].field, + mongoengine.GenericEmbeddedDocumentField, ) ): if getattr(_root, field_name, []) is not None: @@ -464,13 +467,16 @@ def default_resolver(self, _root, info, required_fields=None, resolved=None, **a elif ( isinstance(getattr(self.model, key), mongoengine.fields.ReferenceField) or isinstance( - getattr(self.model, key), mongoengine.fields.GenericReferenceField + getattr(self.model, key), + mongoengine.fields.GenericReferenceField, ) or isinstance( - getattr(self.model, key), mongoengine.fields.LazyReferenceField + getattr(self.model, key), + mongoengine.fields.LazyReferenceField, ) or isinstance( - getattr(self.model, key), mongoengine.fields.CachedReferenceField + getattr(self.model, key), + mongoengine.fields.CachedReferenceField, ) ): if not isinstance(args_copy[key], ObjectId): @@ -603,7 +609,7 @@ def chained_resolver(self, resolver, is_partial, root, info, **args): connection_fields = [ field for field in self.fields - if type(self.fields[field]) == MongoengineConnectionField + if isinstance(self.fields[field], MongoengineConnectionField) ] def filter_connection(x): diff --git a/graphene_mongo/fields_async.py b/graphene_mongo/fields_async.py index 2da93a0..d0cd90f 100644 --- a/graphene_mongo/fields_async.py +++ b/graphene_mongo/fields_async.py @@ -76,7 +76,8 @@ async def default_resolver(self, _root, info, required_fields=None, resolved=Non elif field_name in _root._fields_ordered and not ( isinstance(_root._fields[field_name].field, mongoengine.EmbeddedDocumentField) or isinstance( - _root._fields[field_name].field, mongoengine.GenericEmbeddedDocumentField + _root._fields[field_name].field, + mongoengine.GenericEmbeddedDocumentField, ) ): if getattr(_root, field_name, []) is not None: @@ -170,13 +171,16 @@ async def default_resolver(self, _root, info, required_fields=None, resolved=Non elif ( isinstance(getattr(self.model, key), mongoengine.fields.ReferenceField) or isinstance( - getattr(self.model, key), mongoengine.fields.GenericReferenceField + getattr(self.model, key), + mongoengine.fields.GenericReferenceField, ) or isinstance( - getattr(self.model, key), mongoengine.fields.LazyReferenceField + getattr(self.model, key), + mongoengine.fields.LazyReferenceField, ) or isinstance( - getattr(self.model, key), mongoengine.fields.CachedReferenceField + getattr(self.model, key), + mongoengine.fields.CachedReferenceField, ) ): if not isinstance(args_copy[key], ObjectId): @@ -304,7 +308,7 @@ async def chained_resolver(self, resolver, is_partial, root, info, **args): connection_fields = [ field for field in self.fields - if type(self.fields[field]) == AsyncMongoengineConnectionField + if isinstance(self.fields[field], AsyncMongoengineConnectionField) ] def filter_connection(x): diff --git a/graphene_mongo/tests/test_relay_query_async.py b/graphene_mongo/tests/test_relay_query_async.py index 3b9a542..216750f 100644 --- a/graphene_mongo/tests/test_relay_query_async.py +++ b/graphene_mongo/tests/test_relay_query_async.py @@ -801,7 +801,8 @@ async def test_should_get_queryset_returns_dict_filters_async(fixtures): class Query(graphene.ObjectType): node = Node.Field() articles = AsyncMongoengineConnectionField( - nodes_async.ArticleAsyncNode, get_queryset=lambda *_, **__: {"headline": "World"} + nodes_async.ArticleAsyncNode, + get_queryset=lambda *_, **__: {"headline": "World"}, ) query = """ @@ -1032,7 +1033,9 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio -async def test_should_filter_mongoengine_queryset_by_id_and_other_fields_async(fixtures): +async def test_should_filter_mongoengine_queryset_by_id_and_other_fields_async( + fixtures, +): class Query(graphene.ObjectType): players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) diff --git a/graphene_mongo/tests/types.py b/graphene_mongo/tests/types.py index 684b6ca..45f0017 100644 --- a/graphene_mongo/tests/types.py +++ b/graphene_mongo/tests/types.py @@ -1,5 +1,9 @@ from . import models -from ..types import MongoengineObjectType, MongoengineInterfaceType, MongoengineInputType +from ..types import ( + MongoengineObjectType, + MongoengineInterfaceType, + MongoengineInputType, +) from graphene.types.union import Union diff --git a/graphene_mongo/types_async.py b/graphene_mongo/types_async.py index 4e63508..e82cc58 100644 --- a/graphene_mongo/types_async.py +++ b/graphene_mongo/types_async.py @@ -189,13 +189,17 @@ def resolve_id(self, info): return AsyncGrapheneMongoengineGenericType, AsyncMongoengineGenericObjectTypeOptions -AsyncMongoengineObjectType, AsyncMongoengineObjectTypeOptions = create_graphene_generic_class_async( - ObjectType, ObjectTypeOptions -) +( + AsyncMongoengineObjectType, + AsyncMongoengineObjectTypeOptions, +) = create_graphene_generic_class_async(ObjectType, ObjectTypeOptions) ( AsyncMongoengineInterfaceType, MongoengineInterfaceTypeOptions, ) = create_graphene_generic_class_async(Interface, InterfaceOptions) -AsyncGrapheneMongoengineObjectTypes = (AsyncMongoengineObjectType, AsyncMongoengineInterfaceType) +AsyncGrapheneMongoengineObjectTypes = ( + AsyncMongoengineObjectType, + AsyncMongoengineInterfaceType, +) diff --git a/graphene_mongo/utils.py b/graphene_mongo/utils.py index ffc8422..10ed82d 100644 --- a/graphene_mongo/utils.py +++ b/graphene_mongo/utils.py @@ -256,11 +256,18 @@ def find_skip_and_limit(first, last, after, before, count=None): def connection_from_iterables( - edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type + edges, + start_offset, + has_previous_page, + has_next_page, + connection_type, + edge_type, + pageinfo_type, ): edges_items = [ edge_type( - node=node, cursor=offset_to_cursor((0 if start_offset is None else start_offset) + i) + node=node, + cursor=offset_to_cursor((0 if start_offset is None else start_offset) + i), ) for i, node in enumerate(edges) ]