Skip to content

Commit

Permalink
fix: wrong sync to async wrapper being used
Browse files Browse the repository at this point in the history
  • Loading branch information
mak626 committed Dec 9, 2023
1 parent 51db98f commit 516524d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions graphene_mongo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions graphene_mongo/types_async.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions graphene_mongo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down

0 comments on commit 516524d

Please sign in to comment.