Skip to content

Commit f585518

Browse files
author
Jacob Foster
committed
Account for edges/node nesting in ast
1 parent 17e9bd3 commit f585518

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

graphene_django/optimization.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ def model_fields_as_dict(model):
1717
return dict((f.name, f) for f in model._meta.get_fields())
1818

1919

20+
def find_model_selections(ast):
21+
selections = ast.selection_set.selections
22+
23+
for selection in selections:
24+
if selection.name.value == 'edges':
25+
for sub_selection in selection.selection_set.selections:
26+
if sub_selection.name.value == 'node':
27+
return sub_selection.selection_set.selections
28+
29+
return selections
30+
31+
2032
def get_related_fetches_for_model(model, graphql_ast):
2133
model_fields = model_fields_as_dict(model)
22-
selections = graphql_ast.selection_set.selections
34+
selections = find_model_selections(graphql_ast)
2335

2436
graphene_obj_type = REGISTRY.get_type_for_model(model)
2537
optimizations = {}

0 commit comments

Comments
 (0)