Skip to content

Commit 474abee

Browse files
committed
fix: handle all cases, handle invalid info
1 parent 2313ffe commit 474abee

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

graphene_mongo/utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def get_model_reference_fields(model, excluding=None):
3535
attributes = dict()
3636
for attr_name, attr in model._fields.items():
3737
if attr_name in excluding or not isinstance(
38-
attr,
39-
(mongoengine.fields.ReferenceField, mongoengine.fields.LazyReferenceField),
38+
attr,
39+
(mongoengine.fields.ReferenceField, mongoengine.fields.LazyReferenceField),
4040
):
4141
continue
4242
attributes[attr_name] = attr
@@ -45,7 +45,7 @@ def get_model_reference_fields(model, excluding=None):
4545

4646
def is_valid_mongoengine_model(model):
4747
return inspect.isclass(model) and (
48-
issubclass(model, mongoengine.Document) or issubclass(model, mongoengine.EmbeddedDocument)
48+
issubclass(model, mongoengine.Document) or issubclass(model, mongoengine.EmbeddedDocument)
4949
)
5050

5151

@@ -182,19 +182,18 @@ def has_page_info(info):
182182
info (ResolveInfo)
183183
184184
Returns:
185-
dict: Returned from collect_query_fields
185+
bool: True if it received pageinfo
186186
"""
187187

188188
fragments = {}
189+
if not info:
190+
return True # Returning True if invalid info is provided
189191
node = ast_to_dict(info.field_nodes[0])
190-
191192
for name, value in info.fragments.items():
192193
fragments[name] = ast_to_dict(value)
193194

194195
query = collect_query_fields(node, fragments)
195-
# if "PageInfo" in query:
196-
# return query["edges"]["node"].keys()
197-
return bool("PageInfo" in query)
196+
return next((True for x in query.keys() if x.lower() == "pageinfo"), False)
198197

199198

200199
def ast_to_dict(node, include_loc=False):
@@ -257,7 +256,7 @@ def find_skip_and_limit(first, last, after, before, count=None):
257256

258257

259258
def connection_from_iterables(
260-
edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type
259+
edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type
261260
):
262261
edges_items = [
263262
edge_type(
@@ -281,9 +280,9 @@ def connection_from_iterables(
281280

282281

283282
def sync_to_async(
284-
func: Callable = None,
285-
thread_sensitive: bool = False,
286-
executor: Any = None, # noqa
283+
func: Callable = None,
284+
thread_sensitive: bool = False,
285+
executor: Any = None, # noqa
287286
) -> Union[SyncToAsync, Callable[[Callable[..., Any]], SyncToAsync]]:
288287
"""
289288
Wrapper over sync_to_async from asgiref.sync

0 commit comments

Comments
 (0)