diff --git a/graphene_mongo/converter.py b/graphene_mongo/converter.py index d4ae4856..47c0c78a 100644 --- a/graphene_mongo/converter.py +++ b/graphene_mongo/converter.py @@ -152,7 +152,10 @@ def reference_resolver(root, *args, **kwargs): querying_union_types.remove('__typename') to_resolve_models = list() for each in querying_union_types: - to_resolve_models.append(registry._registry_string_map[each]) + if executor == ExecutorEnum.SYNC: + to_resolve_models.append(registry._registry_string_map[each]) + else: + to_resolve_models.append(registry._registry_async_string_map[each]) to_resolve_object_ids = list() for each in to_resolve: if isinstance(each, LazyReference): @@ -219,7 +222,10 @@ async def reference_resolver_async(root, *args, **kwargs): querying_union_types.remove('__typename') to_resolve_models = list() for each in querying_union_types: - to_resolve_models.append(registry._registry_string_map[each]) + if executor == ExecutorEnum.SYNC: + to_resolve_models.append(registry._registry_string_map[each]) + else: + to_resolve_models.append(registry._registry_async_string_map[each]) to_resolve_object_ids = list() for each in to_resolve: if isinstance(each, LazyReference): @@ -297,7 +303,7 @@ def convert_field_to_union(field, registry=None, executor: ExecutorEnum = Execut elif isinstance(field, mongoengine.GenericEmbeddedDocumentField): _field = mongoengine.EmbeddedDocumentField(choice) - _field = convert_mongoengine_field(_field, registry) + _field = convert_mongoengine_field(_field, registry, executor=executor) _type = _field.get_type() if _type: _types.append(_type.type) @@ -311,7 +317,7 @@ def convert_field_to_union(field, registry=None, executor: ExecutorEnum = Execut name = to_camel_case("{}_{}".format( field._owner_document.__name__, field.db_field - )) + "UnionType" + )) + "UnionType" if ExecutorEnum.SYNC else "AsyncUnionType" Meta = type("Meta", (object,), {"types": tuple(_types)}) _union = type(name, (graphene.Union,), {"Meta": Meta}) @@ -320,7 +326,7 @@ def reference_resolver(root, *args, **kwargs): if de_referenced: document = get_document(de_referenced["_cls"]) document_field = mongoengine.ReferenceField(document) - document_field = convert_mongoengine_field(document_field, registry) + document_field = convert_mongoengine_field(document_field, registry, executor=executor) _type = document_field.get_type().type filter_args = list() if _type._meta.filter_fields: @@ -344,7 +350,7 @@ def lazy_reference_resolver(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - document_field_type = registry.get_type_for_model(document.document_type) + document_field_type = registry.get_type_for_model(document.document_type, executor=executor) querying_types = list(get_query_fields(args[0]).keys()) filter_args = list() if document_field_type._meta.filter_fields: @@ -356,7 +362,7 @@ def lazy_reference_resolver(root, *args, **kwargs): item = to_snake_case(each) if item in document.document_type._fields_ordered + tuple(filter_args): queried_fields.append(item) - _type = registry.get_type_for_model(document.document_type) + _type = registry.get_type_for_model(document.document_type, executor=executor) return document.document_type.objects().no_dereference().only( *(set((list(_type._meta.required_fields) + queried_fields)))).get( pk=document.pk) @@ -393,7 +399,7 @@ async def lazy_reference_resolver_async(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - document_field_type = registry.get_type_for_model(document.document_type) + document_field_type = registry.get_type_for_model(document.document_type, executor=executor) querying_types = list(get_query_fields(args[0]).keys()) filter_args = list() if document_field_type._meta.filter_fields: @@ -405,7 +411,7 @@ async def lazy_reference_resolver_async(root, *args, **kwargs): item = to_snake_case(each) if item in document.document_type._fields_ordered + tuple(filter_args): queried_fields.append(item) - _type = registry.get_type_for_model(document.document_type) + _type = registry.get_type_for_model(document.document_type, executor=executor) return await sync_to_async(document.document_type.objects().no_dereference().only( *(set((list(_type._meta.required_fields) + queried_fields)))).get, thread_sensitive=False, executor=ThreadPoolExecutor())(pk=document.pk) @@ -418,7 +424,8 @@ async def lazy_reference_resolver_async(root, *args, **kwargs): required = False if field.db_field is not None: required = field.required - resolver_function = getattr(registry.get_type_for_model(field.owner_document), "resolve_" + field.db_field, + resolver_function = getattr(registry.get_type_for_model(field.owner_document, executor=executor), + "resolve_" + field.db_field, None) if resolver_function and callable(resolver_function): field_resolver = resolver_function @@ -431,7 +438,8 @@ async def lazy_reference_resolver_async(root, *args, **kwargs): required = False if field.db_field is not None: required = field.required - resolver_function = getattr(registry.get_type_for_model(field.owner_document), "resolve_" + field.db_field, + resolver_function = getattr(registry.get_type_for_model(field.owner_document, executor=executor), + "resolve_" + field.db_field, None) if resolver_function and callable(resolver_function): field_resolver = resolver_function @@ -452,7 +460,7 @@ def reference_resolver(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - _type = registry.get_type_for_model(field.document_type) + _type = registry.get_type_for_model(field.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -470,7 +478,7 @@ def reference_resolver(root, *args, **kwargs): def cached_reference_resolver(root, *args, **kwargs): if field: queried_fields = list() - _type = registry.get_type_for_model(field.document_type) + _type = registry.get_type_for_model(field.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -490,7 +498,7 @@ async def reference_resolver_async(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - _type = registry.get_type_for_model(field.document_type) + _type = registry.get_type_for_model(field.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -508,7 +516,7 @@ async def reference_resolver_async(root, *args, **kwargs): async def cached_reference_resolver_async(root, *args, **kwargs): if field: queried_fields = list() - _type = registry.get_type_for_model(field.document_type) + _type = registry.get_type_for_model(field.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -526,7 +534,7 @@ async def cached_reference_resolver_async(root, *args, **kwargs): return None def dynamic_type(): - _type = registry.get_type_for_model(model) + _type = registry.get_type_for_model(model, executor=executor) if not _type: return None if isinstance(field, mongoengine.EmbeddedDocumentField): @@ -536,7 +544,8 @@ def dynamic_type(): required = False if field.db_field is not None: required = field.required - resolver_function = getattr(registry.get_type_for_model(field.owner_document), "resolve_" + field.db_field, + resolver_function = getattr(registry.get_type_for_model(field.owner_document, executor=executor), + "resolve_" + field.db_field, None) if resolver_function and callable(resolver_function): field_resolver = resolver_function @@ -560,7 +569,7 @@ def lazy_resolver(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - _type = registry.get_type_for_model(document.document_type) + _type = registry.get_type_for_model(document.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -579,7 +588,7 @@ async def lazy_resolver_async(root, *args, **kwargs): document = getattr(root, field.name or field.db_name) if document: queried_fields = list() - _type = registry.get_type_for_model(document.document_type) + _type = registry.get_type_for_model(document.document_type, executor=executor) filter_args = list() if _type._meta.filter_fields: for key, values in _type._meta.filter_fields.items(): @@ -595,14 +604,15 @@ async def lazy_resolver_async(root, *args, **kwargs): return None def dynamic_type(): - _type = registry.get_type_for_model(model) + _type = registry.get_type_for_model(model, executor=executor) if not _type: return None field_resolver = None required = False if field.db_field is not None: required = field.required - resolver_function = getattr(registry.get_type_for_model(field.owner_document), "resolve_" + field.db_field, + resolver_function = getattr(registry.get_type_for_model(field.owner_document, executor=executor), + "resolve_" + field.db_field, None) if resolver_function and callable(resolver_function): field_resolver = resolver_function diff --git a/graphene_mongo/fields_async.py b/graphene_mongo/fields_async.py index 6e59fe65..bf3daafd 100644 --- a/graphene_mongo/fields_async.py +++ b/graphene_mongo/fields_async.py @@ -34,12 +34,6 @@ class AsyncMongoengineConnectionField(MongoengineConnectionField): def __init__(self, type, *args, **kwargs): - get_queryset = kwargs.pop("get_queryset", None) - if get_queryset: - assert callable( - get_queryset - ), "Attribute `get_queryset` on {} must be callable.".format(self) - self._get_queryset = get_queryset super(AsyncMongoengineConnectionField, self).__init__(type, *args, **kwargs) @property diff --git a/graphene_mongo/registry.py b/graphene_mongo/registry.py index a7aa61d3..feea4d0a 100644 --- a/graphene_mongo/registry.py +++ b/graphene_mongo/registry.py @@ -1,10 +1,14 @@ from graphene import Enum +from graphene_mongo.utils import ExecutorEnum + class Registry(object): def __init__(self): self._registry = {} + self._registry_async = {} self._registry_string_map = {} + self._registry_async_string_map = {} self._registry_enum = {} def register(self, cls): @@ -21,8 +25,12 @@ def register(self, cls): cls.__name__ ) assert cls._meta.registry == self, "Registry for a Model have to match." - self._registry[cls._meta.model] = cls - self._registry_string_map[cls.__name__] = cls._meta.model.__name__ + if issubclass(cls, GrapheneMongoengineObjectTypes): + self._registry[cls._meta.model] = cls + self._registry_string_map[cls.__name__] = cls._meta.model.__name__ + else: + self._registry_async[cls._meta.model] = cls + self._registry_async_string_map[cls.__name__] = cls._meta.model.__name__ # Rescan all fields for model, cls in self._registry.items(): @@ -40,8 +48,11 @@ def register_enum(self, cls): cls.__name__ = name self._registry_enum[cls] = Enum.from_enum(cls) - def get_type_for_model(self, model): - return self._registry.get(model) + def get_type_for_model(self, model, executor: ExecutorEnum = ExecutorEnum.SYNC): + if executor == ExecutorEnum.SYNC: + return self._registry.get(model) + else: + return self._registry_async.get(model) def check_enum_already_exist(self, cls): return cls in self._registry_enum diff --git a/graphene_mongo/tests/nodes.py b/graphene_mongo/tests/nodes.py index 3053f300..ef98cad1 100644 --- a/graphene_mongo/tests/nodes.py +++ b/graphene_mongo/tests/nodes.py @@ -3,6 +3,7 @@ from . import models from . import types # noqa: F401 +from .models import ProfessorMetadata from ..types_async import AsyncMongoengineObjectType from ..types import MongoengineObjectType @@ -48,12 +49,6 @@ class Meta: interfaces = (Node,) -class ReporterNodeAsync(AsyncMongoengineObjectType): - class Meta: - model = models.Reporter - interfaces = (Node,) - - class ParentNode(MongoengineObjectType): class Meta: model = models.Parent @@ -72,16 +67,22 @@ class Meta: interfaces = (Node,) +class ChildRegisteredAfterNode(MongoengineObjectType): + class Meta: + model = models.ChildRegisteredAfter + interfaces = (Node,) + + class ParentWithRelationshipNode(MongoengineObjectType): class Meta: model = models.ParentWithRelationship interfaces = (Node,) -class ChildRegisteredAfterNode(MongoengineObjectType): +class ProfessorMetadataNode(MongoengineObjectType): class Meta: - model = models.ChildRegisteredAfter - interfaces = (Node,) + model = ProfessorMetadata + interfaces = (graphene.Node,) class ProfessorVectorNode(MongoengineObjectType): diff --git a/graphene_mongo/tests/nodes_async.py b/graphene_mongo/tests/nodes_async.py index ac7fb95e..a38635ce 100644 --- a/graphene_mongo/tests/nodes_async.py +++ b/graphene_mongo/tests/nodes_async.py @@ -3,10 +3,11 @@ from . import models from . import types # noqa: F401 +from .models import ProfessorMetadata from ..types_async import AsyncMongoengineObjectType -class PublisherNode(AsyncMongoengineObjectType): +class PublisherAsyncNode(AsyncMongoengineObjectType): legal_name = graphene.String() bad_field = graphene.String() @@ -16,92 +17,92 @@ class Meta: interfaces = (Node,) -class ArticleNode(AsyncMongoengineObjectType): +class ArticleAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Article interfaces = (Node,) -class EditorNode(AsyncMongoengineObjectType): +class EditorAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Editor interfaces = (Node,) -class EmbeddedArticleNode(AsyncMongoengineObjectType): +class EmbeddedArticleAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.EmbeddedArticle interfaces = (Node,) -class PlayerNode(AsyncMongoengineObjectType): +class PlayerAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Player interfaces = (Node,) filter_fields = {"first_name": ["istartswith", "in"]} -class ReporterNode(AsyncMongoengineObjectType): +class ReporterAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Reporter interfaces = (Node,) -class ReporterNodeAsync(AsyncMongoengineObjectType): +class ParentAsyncNode(AsyncMongoengineObjectType): class Meta: - model = models.Reporter + model = models.Parent interfaces = (Node,) -class ParentNode(AsyncMongoengineObjectType): +class ChildAsyncNode(AsyncMongoengineObjectType): class Meta: - model = models.Parent + model = models.Child interfaces = (Node,) -class ChildNode(AsyncMongoengineObjectType): +class ChildRegisteredBeforeAsyncNode(AsyncMongoengineObjectType): class Meta: - model = models.Child + model = models.ChildRegisteredBefore interfaces = (Node,) -class ChildRegisteredBeforeNode(AsyncMongoengineObjectType): +class ChildRegisteredAfterAsyncNode(AsyncMongoengineObjectType): class Meta: - model = models.ChildRegisteredBefore + model = models.ChildRegisteredAfter interfaces = (Node,) -class ParentWithRelationshipNode(AsyncMongoengineObjectType): +class ParentWithRelationshipAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.ParentWithRelationship interfaces = (Node,) -class ChildRegisteredAfterNode(AsyncMongoengineObjectType): +class ProfessorMetadataAsyncNode(AsyncMongoengineObjectType): class Meta: - model = models.ChildRegisteredAfter - interfaces = (Node,) + model = ProfessorMetadata + interfaces = (graphene.Node,) -class ProfessorVectorNode(AsyncMongoengineObjectType): +class ProfessorVectorAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.ProfessorVector interfaces = (Node,) -class ErroneousModelNode(AsyncMongoengineObjectType): +class ErroneousModelAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.ErroneousModel interfaces = (Node,) -class BarNode(AsyncMongoengineObjectType): +class BarAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Bar interfaces = (Node,) -class FooNode(AsyncMongoengineObjectType): +class FooAsyncNode(AsyncMongoengineObjectType): class Meta: model = models.Foo interfaces = (Node,) diff --git a/graphene_mongo/tests/test_relay_query.py b/graphene_mongo/tests/test_relay_query.py index 9824477a..1e2d7ba3 100644 --- a/graphene_mongo/tests/test_relay_query.py +++ b/graphene_mongo/tests/test_relay_query.py @@ -9,7 +9,6 @@ from . import models from . import nodes -from .. import AsyncMongoengineConnectionField from ..fields import MongoengineConnectionField from ..types import MongoengineObjectType diff --git a/graphene_mongo/tests/test_relay_query_async.py b/graphene_mongo/tests/test_relay_query_async.py index 71c66b34..83b62ba4 100644 --- a/graphene_mongo/tests/test_relay_query_async.py +++ b/graphene_mongo/tests/test_relay_query_async.py @@ -10,14 +10,12 @@ from . import models from . import nodes_async from .. import AsyncMongoengineConnectionField, AsyncMongoengineObjectType -from ..fields import MongoengineConnectionField -from ..types import MongoengineObjectType @pytest.mark.asyncio async def test_should_query_reporter_async(fixtures): class Query(graphene.ObjectType): - reporter = graphene.Field(nodes_async.ReporterNode) + reporter = graphene.Field(nodes_async.ReporterAsyncNode) async def resolve_reporter(self, *args, **kwargs): return models.Reporter.objects.no_dereference().first() @@ -52,7 +50,7 @@ async def resolve_reporter(self, *args, **kwargs): }, genericReference { __typename - ... on ArticleNode { + ... on ArticleAsyncNode { headline } } @@ -83,7 +81,7 @@ async def resolve_reporter(self, *args, **kwargs): {"node": {"headline": "Real"}}, ] }, - "genericReference": {"__typename": "ArticleNode", "headline": "Hello"}, + "genericReference": {"__typename": "ArticleAsyncNode", "headline": "Hello"}, } } @@ -96,7 +94,7 @@ async def resolve_reporter(self, *args, **kwargs): @pytest.mark.asyncio async def test_should_query_reporters_with_nested_document_async(fixtures): class Query(graphene.ObjectType): - reporters = AsyncMongoengineConnectionField(nodes_async.ReporterNode) + reporters = AsyncMongoengineConnectionField(nodes_async.ReporterAsyncNode) query = """ query ReporterQuery { @@ -142,7 +140,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_query_all_editors_async(fixtures, fixtures_dirname): class Query(graphene.ObjectType): - editors = AsyncMongoengineConnectionField(nodes_async.EditorNode) + editors = AsyncMongoengineConnectionField(nodes_async.EditorAsyncNode) query = """ query EditorQuery { @@ -172,7 +170,7 @@ class Query(graphene.ObjectType): "edges": [ { "node": { - "id": "RWRpdG9yTm9kZTox", + "id": "RWRpdG9yQXN5bmNOb2RlOjE=", "firstName": "Penny", "lastName": "Hardaway", "avatar": { @@ -184,7 +182,7 @@ class Query(graphene.ObjectType): }, { "node": { - "id": "RWRpdG9yTm9kZToy", + "id": "RWRpdG9yQXN5bmNOb2RlOjI=", "firstName": "Grant", "lastName": "Hill", "avatar": {"contentType": None, "length": 0, "data": None}, @@ -192,7 +190,7 @@ class Query(graphene.ObjectType): }, { "node": { - "id": "RWRpdG9yTm9kZToz", + "id": "RWRpdG9yQXN5bmNOb2RlOjM=", "firstName": "Dennis", "lastName": "Rodman", "avatar": {"contentType": None, "length": 0, "data": None}, @@ -213,7 +211,7 @@ async def test_should_query_editors_with_dataloader_async(fixtures): from promise.dataloader import DataLoader class ArticleLoader(DataLoader): - async def batch_load_fn(self, instances): + def batch_load_fn(self, instances): queryset = models.Article.objects(editor__in=instances) return Promise.resolve( [ @@ -229,7 +227,7 @@ class Meta: model = models.Editor interfaces = (graphene.Node,) - articles = AsyncMongoengineConnectionField(nodes_async.ArticleNode) + articles = AsyncMongoengineConnectionField(nodes_async.ArticleAsyncNode) async def resolve_articles(self, *args, **kwargs): return article_loader.load(self) @@ -277,11 +275,11 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_filter_editors_by_id_async(fixtures): class Query(graphene.ObjectType): - editors = AsyncMongoengineConnectionField(nodes_async.EditorNode) + editors = AsyncMongoengineConnectionField(nodes_async.EditorAsyncNode) query = """ query EditorQuery { - editors(id: "RWRpdG9yTm9kZToy") { + editors(id: "RWRpdG9yQXN5bmNOb2RlOjI=") { edges { node { id, @@ -297,7 +295,7 @@ class Query(graphene.ObjectType): "edges": [ { "node": { - "id": "RWRpdG9yTm9kZToy", + "id": "RWRpdG9yQXN5bmNOb2RlOjI=", "firstName": "Grant", "lastName": "Hill", } @@ -314,7 +312,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_filter_async(fixtures): class Query(graphene.ObjectType): - articles = AsyncMongoengineConnectionField(nodes_async.ArticleNode) + articles = AsyncMongoengineConnectionField(nodes_async.ArticleAsyncNode) query = """ query ArticlesQuery { @@ -353,7 +351,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_filter_by_reference_field_async(fixtures): class Query(graphene.ObjectType): - articles = AsyncMongoengineConnectionField(nodes_async.ArticleNode) + articles = AsyncMongoengineConnectionField(nodes_async.ArticleAsyncNode) query = """ query ArticlesQuery { @@ -384,7 +382,7 @@ class Query(graphene.ObjectType): async def test_should_filter_through_inheritance_async(fixtures): class Query(graphene.ObjectType): node = Node.Field() - children = AsyncMongoengineConnectionField(nodes_async.ChildNode) + children = AsyncMongoengineConnectionField(nodes_async.ChildAsyncNode) query = """ query ChildrenQuery { @@ -425,7 +423,7 @@ class Query(graphene.ObjectType): async def test_should_filter_by_list_contains_async(fixtures): # Notes: https://goo.gl/hMNRgs class Query(graphene.ObjectType): - reporters = AsyncMongoengineConnectionField(nodes_async.ReporterNodeAsync) + reporters = AsyncMongoengineConnectionField(nodes_async.ReporterAsyncNode) query = """ query ReportersQuery { @@ -437,7 +435,7 @@ class Query(graphene.ObjectType): awards, genericReferences { __typename - ... on ArticleNode { + ... on ArticleAsyncNode { headline } } @@ -451,12 +449,12 @@ class Query(graphene.ObjectType): "edges": [ { "node": { - "id": "UmVwb3J0ZXJOb2RlQXN5bmM6MQ==", + "id": "UmVwb3J0ZXJBc3luY05vZGU6MQ==", "firstName": "Allen", "awards": ["2010-mvp"], "genericReferences": [ { - "__typename": "ArticleNode", + "__typename": "ArticleAsyncNode", "headline": "Hello" } ] @@ -475,11 +473,11 @@ class Query(graphene.ObjectType): async def test_should_filter_by_id_async(fixtures): # Notes: https://goo.gl/hMNRgs class Query(graphene.ObjectType): - reporter = Node.Field(nodes_async.ReporterNode) + reporter = Node.Field(nodes_async.ReporterAsyncNode) query = """ query ReporterQuery { - reporter (id: "UmVwb3J0ZXJOb2RlOjE=") { + reporter (id: "UmVwb3J0ZXJBc3luY05vZGU6MQ==") { id, firstName, awards @@ -488,7 +486,7 @@ class Query(graphene.ObjectType): """ expected = { "reporter": { - "id": "UmVwb3J0ZXJOb2RlOjE=", + "id": "UmVwb3J0ZXJBc3luY05vZGU6MQ==", "firstName": "Allen", "awards": ["2010-mvp"], } @@ -502,7 +500,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_first_n_async(fixtures): class Query(graphene.ObjectType): - editors = AsyncMongoengineConnectionField(nodes_async.EditorNode) + editors = AsyncMongoengineConnectionField(nodes_async.EditorAsyncNode) query = """ query EditorQuery { @@ -546,7 +544,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_after_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query EditorQuery { @@ -579,7 +577,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_before_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query EditorQuery { @@ -614,7 +612,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_last_n_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query PlayerQuery { @@ -646,7 +644,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_self_reference_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query PlayersQuery { @@ -722,9 +720,10 @@ class Query(graphene.ObjectType): async def test_should_lazy_reference_async(fixtures): class Query(graphene.ObjectType): node = Node.Field() - parents = AsyncMongoengineConnectionField(nodes_async.ParentWithRelationshipNode) + parents = AsyncMongoengineConnectionField(nodes_async.ParentWithRelationshipAsyncNode) schema = graphene.Schema(query=Query) + print(schema) query = """ query { @@ -782,7 +781,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_query_with_embedded_document_async(fixtures): class Query(graphene.ObjectType): - professors = AsyncMongoengineConnectionField(nodes_async.ProfessorVectorNode) + professors = AsyncMongoengineConnectionField(nodes_async.ProfessorVectorAsyncNode) query = """ query { @@ -816,7 +815,7 @@ async def test_should_get_queryset_returns_dict_filters_async(fixtures): class Query(graphene.ObjectType): node = Node.Field() articles = AsyncMongoengineConnectionField( - nodes_async.ArticleNode, get_queryset=lambda *_, **__: {"headline": "World"} + nodes_async.ArticleAsyncNode, get_queryset=lambda *_, **__: {"headline": "World"} ) query = """ @@ -855,13 +854,13 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_get_queryset_returns_qs_filters_async(fixtures): - async def get_queryset(model, info, **args): + def get_queryset(model, info, **args): return model.objects(headline="World") class Query(graphene.ObjectType): node = Node.Field() articles = AsyncMongoengineConnectionField( - nodes_async.ArticleNode, get_queryset=get_queryset + nodes_async.ArticleAsyncNode, get_queryset=get_queryset ) query = """ @@ -901,7 +900,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_filter_mongoengine_queryset_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query players { @@ -934,7 +933,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_query_document_with_embedded_async(fixtures): class Query(graphene.ObjectType): - foos = AsyncMongoengineConnectionField(nodes_async.FooNode) + foos = AsyncMongoengineConnectionField(nodes_async.FooAsyncNode) async def resolve_multiple_foos(self, *args, **kwargs): return list(models.Foo.objects.all()) @@ -965,7 +964,7 @@ async def resolve_multiple_foos(self, *args, **kwargs): @pytest.mark.asyncio async def test_should_filter_mongoengine_queryset_with_list_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query players { @@ -998,7 +997,7 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_get_correct_list_of_documents_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) query = """ query players { @@ -1048,10 +1047,10 @@ class Query(graphene.ObjectType): @pytest.mark.asyncio async def test_should_filter_mongoengine_queryset_by_id_and_other_fields_async(fixtures): class Query(graphene.ObjectType): - players = AsyncMongoengineConnectionField(nodes_async.PlayerNode) + players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode) larry = models.Player.objects.get(first_name="Larry") - larry_relay_id = to_global_id("PlayerNode", larry.id) + larry_relay_id = to_global_id("PlayerAsyncNode", larry.id) # "Larry" id && firstName == "Michael" should return nothing query = """