Skip to content

Commit

Permalink
Bug Fix: Argument Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsureshkumar committed Apr 12, 2023
1 parent 55d9eb6 commit 2b2813d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
14 changes: 11 additions & 3 deletions graphene_mongo/fields_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand All @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions graphene_mongo/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,36 @@ 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:
registry = 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
13 changes: 8 additions & 5 deletions graphene_mongo/types_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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)

0 comments on commit 2b2813d

Please sign in to comment.