From 516524dc0ba123bf7aaf78c92fa013839de23dcd Mon Sep 17 00:00:00 2001 From: M Aswin Kishore Date: Sat, 9 Dec 2023 11:29:45 +0530 Subject: [PATCH] fix: wrong sync to async wrapper being used --- README.md | 2 +- graphene_mongo/types.py | 13 +++++++++---- graphene_mongo/types_async.py | 3 +-- graphene_mongo/utils.py | 6 +++--- pyproject.toml | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index abc2f42f..445f00bb 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ To create a GraphQL schema and async executor; for it you simply have to write t import graphene from graphene_mongo import AsyncMongoengineObjectType -from asgiref.sync import sync_to_async +from graphene_mongo.utils import sync_to_async from concurrent.futures import ThreadPoolExecutor from .models import User as UserModel diff --git a/graphene_mongo/types.py b/graphene_mongo/types.py index 4eeda046..b3cebcfc 100644 --- a/graphene_mongo/types.py +++ b/graphene_mongo/types.py @@ -3,18 +3,23 @@ import graphene import mongoengine -from asgiref.sync import sync_to_async from graphene.relay import Connection, Node -from graphene.types.objecttype import ObjectType, ObjectTypeOptions from graphene.types.inputobjecttype import InputObjectType, InputObjectTypeOptions from graphene.types.interface import Interface, InterfaceOptions +from graphene.types.objecttype import ObjectType, ObjectTypeOptions from graphene.types.utils import yank_fields_from_attrs from graphene.utils.str_converters import to_snake_case -from graphene_mongo import MongoengineConnectionField +from graphene_mongo import MongoengineConnectionField from .converter import convert_mongoengine_field from .registry import Registry, get_global_registry, get_inputs_registry -from .utils import get_model_fields, is_valid_mongoengine_model, get_query_fields, ExecutorEnum +from .utils import ( + ExecutorEnum, + get_model_fields, + get_query_fields, + is_valid_mongoengine_model, + sync_to_async, +) def construct_fields( diff --git a/graphene_mongo/types_async.py b/graphene_mongo/types_async.py index 033cd9e1..4e635085 100644 --- a/graphene_mongo/types_async.py +++ b/graphene_mongo/types_async.py @@ -1,6 +1,5 @@ import graphene import mongoengine -from asgiref.sync import sync_to_async from graphene import InputObjectType from graphene.relay import Connection, Node from graphene.types.interface import Interface, InterfaceOptions @@ -11,7 +10,7 @@ from graphene_mongo import AsyncMongoengineConnectionField from .registry import Registry, get_global_async_registry, get_inputs_async_registry from .types import construct_fields, construct_self_referenced_fields -from .utils import ExecutorEnum, get_query_fields, is_valid_mongoengine_model +from .utils import ExecutorEnum, get_query_fields, is_valid_mongoengine_model, sync_to_async def create_graphene_generic_class_async(object_type, option_type): diff --git a/graphene_mongo/utils.py b/graphene_mongo/utils.py index 1c4e31a7..17cd82b6 100644 --- a/graphene_mongo/utils.py +++ b/graphene_mongo/utils.py @@ -4,10 +4,10 @@ import inspect from collections import OrderedDict from concurrent.futures import ThreadPoolExecutor -from typing import Any, Callable, Union +from typing import Any, Callable, Coroutine, ParamSpec import mongoengine -from asgiref.sync import SyncToAsync, sync_to_async as asgiref_sync_to_async +from asgiref.sync import sync_to_async as asgiref_sync_to_async from graphene import Node from graphene.utils.trim_docstring import trim_docstring from graphql import FieldNode @@ -260,7 +260,7 @@ def sync_to_async( func: Callable = None, thread_sensitive: bool = False, executor: Any = None, # noqa -) -> Union[SyncToAsync, Callable[[Callable[..., Any]], SyncToAsync]]: +) -> Callable[[ParamSpec("_P")], Coroutine[Any, Any, Any]]: """ Wrapper over sync_to_async from asgiref.sync Defaults to thread insensitive with ThreadPoolExecutor of n workers diff --git a/pyproject.toml b/pyproject.toml index 13d89355..86d33984 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "graphene-mongo" packages = [{ include = "graphene_mongo" }] -version = "0.4.2" +version = "0.4.3" description = "Graphene Mongoengine integration" authors = [ "Abaw Chen ",