Skip to content

Commit

Permalink
fix: handle all cases, handle invalid info
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinand-c committed Dec 9, 2023
1 parent 2313ffe commit 474abee
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions graphene_mongo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def get_model_reference_fields(model, excluding=None):
attributes = dict()
for attr_name, attr in model._fields.items():
if attr_name in excluding or not isinstance(
attr,
(mongoengine.fields.ReferenceField, mongoengine.fields.LazyReferenceField),
attr,
(mongoengine.fields.ReferenceField, mongoengine.fields.LazyReferenceField),
):
continue
attributes[attr_name] = attr
Expand All @@ -45,7 +45,7 @@ def get_model_reference_fields(model, excluding=None):

def is_valid_mongoengine_model(model):
return inspect.isclass(model) and (
issubclass(model, mongoengine.Document) or issubclass(model, mongoengine.EmbeddedDocument)
issubclass(model, mongoengine.Document) or issubclass(model, mongoengine.EmbeddedDocument)
)


Expand Down Expand Up @@ -182,19 +182,18 @@ def has_page_info(info):
info (ResolveInfo)
Returns:
dict: Returned from collect_query_fields
bool: True if it received pageinfo
"""

fragments = {}
if not info:
return True # Returning True if invalid info is provided
node = ast_to_dict(info.field_nodes[0])

for name, value in info.fragments.items():
fragments[name] = ast_to_dict(value)

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


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


def connection_from_iterables(
edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type
edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type
):
edges_items = [
edge_type(
Expand All @@ -281,9 +280,9 @@ def connection_from_iterables(


def sync_to_async(
func: Callable = None,
thread_sensitive: bool = False,
executor: Any = None, # noqa
func: Callable = None,
thread_sensitive: bool = False,
executor: Any = None, # noqa
) -> Union[SyncToAsync, Callable[[Callable[..., Any]], SyncToAsync]]:
"""
Wrapper over sync_to_async from asgiref.sync
Expand Down

0 comments on commit 474abee

Please sign in to comment.