Skip to content

Commit 4d29d83

Browse files
committed
Rename type to runtime_type in collect_fields function.
1 parent 7938e1b commit 4d29d83

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

graphql/core/execution/base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ def get_operation_root_type(schema, operation):
148148
)
149149

150150

151-
def collect_fields(ctx, type, selection_set, fields, prev_fragment_names):
151+
def collect_fields(ctx, runtime_type, selection_set, fields, prev_fragment_names):
152+
"""
153+
Given a selectionSet, adds all of the fields in that selection to
154+
the passed in map of fields, and returns it at the end.
155+
156+
collect_fields requires the "runtime type" of an object. For a field which
157+
returns and Interface or Union type, the "runtime type" will be the actual
158+
Object type returned by that field.
159+
"""
152160
for selection in selection_set.selections:
153161
directives = selection.directives
154162

@@ -160,10 +168,10 @@ def collect_fields(ctx, type, selection_set, fields, prev_fragment_names):
160168
fields[name].append(selection)
161169

162170
elif isinstance(selection, ast.InlineFragment):
163-
if not should_include_node(ctx, directives) or not does_fragment_condition_match(ctx, selection, type):
171+
if not should_include_node(ctx, directives) or not does_fragment_condition_match(ctx, selection, runtime_type):
164172
continue
165173

166-
collect_fields(ctx, type, selection.selection_set, fields, prev_fragment_names)
174+
collect_fields(ctx, runtime_type, selection.selection_set, fields, prev_fragment_names)
167175

168176
elif isinstance(selection, ast.FragmentSpread):
169177
frag_name = selection.name.value
@@ -176,10 +184,10 @@ def collect_fields(ctx, type, selection_set, fields, prev_fragment_names):
176184
frag_directives = fragment.directives
177185
if not fragment or not \
178186
should_include_node(ctx, frag_directives) or not \
179-
does_fragment_condition_match(ctx, fragment, type):
187+
does_fragment_condition_match(ctx, fragment, runtime_type):
180188
continue
181189

182-
collect_fields(ctx, type, fragment.selection_set, fields, prev_fragment_names)
190+
collect_fields(ctx, runtime_type, fragment.selection_set, fields, prev_fragment_names)
183191

184192
return fields
185193

graphql/core/execution/executor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
302302
if selection_set:
303303
subfield_asts = collect_fields(
304304
ctx, runtime_type, selection_set,
305-
subfield_asts, visited_fragment_names)
305+
subfield_asts, visited_fragment_names
306+
)
306307

307308
return self._execute_fields(ctx, runtime_type, result, subfield_asts)
308309

0 commit comments

Comments
 (0)