diff --git a/graphene_mongo/fields.py b/graphene_mongo/fields.py index 41a74890..36c808fe 100644 --- a/graphene_mongo/fields.py +++ b/graphene_mongo/fields.py @@ -124,6 +124,8 @@ def is_filterable(k): Returns: bool """ + if k == "attractions": + a = k if hasattr(self.fields[k].type, '_sdl'): return False if not hasattr(self.model, k): diff --git a/graphene_mongo/fields_async.py b/graphene_mongo/fields_async.py index c09b1266..70d40d49 100644 --- a/graphene_mongo/fields_async.py +++ b/graphene_mongo/fields_async.py @@ -16,10 +16,10 @@ from pymongo.errors import OperationFailure from asgiref.sync import sync_to_async from concurrent.futures import ThreadPoolExecutor - +from .registry import get_global_async_registry from . import MongoengineConnectionField from .utils import get_query_fields, find_skip_and_limit, \ - connection_from_iterables + connection_from_iterables, ExecutorEnum import pymongo PYMONGO_VERSION = tuple(pymongo.version_tuple[:2]) @@ -29,6 +29,10 @@ class AsyncMongoengineConnectionField(MongoengineConnectionField): def __init__(self, type, *args, **kwargs): super(AsyncMongoengineConnectionField, self).__init__(type, *args, **kwargs) + @property + def executor(self): + return ExecutorEnum.ASYNC + @property def type(self): from .types_async import AsyncMongoengineObjectType @@ -44,7 +48,11 @@ def type(self): @property def fields(self): - return super().fields + return super(AsyncMongoengineConnectionField, self).fields + + @property + def registry(self): + return getattr(self.node_type._meta, "registry", get_global_async_registry()) async def default_resolver(self, _root, info, required_fields=None, resolved=None, **args): if required_fields is None: diff --git a/graphene_mongo/registry.py b/graphene_mongo/registry.py index feea4d0a..62fd0cea 100644 --- a/graphene_mongo/registry.py +++ b/graphene_mongo/registry.py @@ -74,6 +74,13 @@ def get_inputs_registry(): return inputs_registry +def get_inputs_async_registry(): + global async_inputs_registry + if not async_inputs_registry: + async_inputs_registry = Registry() + return async_inputs_registry + + def get_global_registry(): global registry if not registry: @@ -81,8 +88,22 @@ def get_global_registry(): return registry +def get_global_async_registry(): + global async_registry + if not async_registry: + async_registry = Registry() + return async_registry + + def reset_global_registry(): global registry global inputs_registry registry = None inputs_registry = None + + +def reset_global_async_registry(): + global async_registry + global async_inputs_registry + async_registry = None + async_inputs_registry = None diff --git a/graphene_mongo/types_async.py b/graphene_mongo/types_async.py index da6e2bbf..1fcb6b51 100644 --- a/graphene_mongo/types_async.py +++ b/graphene_mongo/types_async.py @@ -4,12 +4,13 @@ from graphene import InputObjectType from graphene.relay import Connection, Node from graphene.types.objecttype import ObjectType, ObjectTypeOptions +from graphene.types.interface import Interface, InterfaceOptions from graphene.types.utils import yank_fields_from_attrs from graphene.utils.str_converters import to_snake_case from graphene_mongo import AsyncMongoengineConnectionField -from .registry import Registry, get_global_registry, \ - get_inputs_registry +from .registry import Registry, get_global_async_registry, \ + get_inputs_async_registry from .types import construct_fields, construct_self_referenced_fields from .utils import is_valid_mongoengine_model, get_query_fields, ExecutorEnum @@ -55,9 +56,9 @@ def __init_subclass_with_meta__( if not registry: # input objects shall be registred in a separated registry if issubclass(cls, InputObjectType): - registry = get_inputs_registry() + registry = get_inputs_async_registry() else: - registry = get_global_registry() + registry = get_global_async_registry() assert isinstance(registry, Registry), ( "The attribute registry in {}.Meta needs to be an instance of " @@ -192,5 +193,7 @@ def resolve_id(self, info): AsyncMongoengineObjectType, AsyncMongoengineObjectTypeOptions = create_graphene_generic_class_async(ObjectType, ObjectTypeOptions) +AsyncMongoengineInterfaceType, MongoengineInterfaceTypeOptions = create_graphene_generic_class_async(Interface, + InterfaceOptions) -AsyncGrapheneMongoengineObjectTypes = (AsyncMongoengineObjectType,) +AsyncGrapheneMongoengineObjectTypes = (AsyncMongoengineObjectType, AsyncMongoengineInterfaceType)