4
4
5
5
from graphene .types .json import JSONString
6
6
from graphene .utils .str_converters import to_snake_case
7
- from mongoengine .base import get_document
7
+ from mongoengine .base import get_document , LazyReference
8
8
from . import advanced_types
9
9
from .utils import import_single_dispatch , get_field_description , get_query_fields
10
10
from concurrent .futures import ThreadPoolExecutor , as_completed
@@ -138,10 +138,19 @@ def reference_resolver(root, *args, **kwargs):
138
138
to_resolve_models = list ()
139
139
for each in querying_union_types :
140
140
to_resolve_models .append (registry ._registry_string_map [each ])
141
+ to_resolve_object_ids = list ()
141
142
for each in to_resolve :
142
- if each ['_cls' ] not in choice_to_resolve :
143
- choice_to_resolve [each ['_cls' ]] = list ()
144
- choice_to_resolve [each ['_cls' ]].append (each ["_ref" ].id )
143
+ if isinstance (each , LazyReference ):
144
+ to_resolve_object_ids .append (each .pk )
145
+ model = each .document_type ._class_name
146
+ if model not in choice_to_resolve :
147
+ choice_to_resolve [model ] = list ()
148
+ choice_to_resolve [model ].append (each .pk )
149
+ else :
150
+ to_resolve_object_ids .append (each ["_ref" ].id )
151
+ if each ['_cls' ] not in choice_to_resolve :
152
+ choice_to_resolve [each ['_cls' ]] = list ()
153
+ choice_to_resolve [each ['_cls' ]].append (each ["_ref" ].id )
145
154
pool = ThreadPoolExecutor (5 )
146
155
futures = list ()
147
156
for model , object_id_list in choice_to_resolve .items ():
@@ -153,7 +162,6 @@ def reference_resolver(root, *args, **kwargs):
153
162
result = list ()
154
163
for x in as_completed (futures ):
155
164
result += x .result ()
156
- to_resolve_object_ids = [each ["_ref" ].id for each in to_resolve ]
157
165
result_object_ids = list ()
158
166
for each in result :
159
167
result_object_ids .append (each .id )
0 commit comments