@@ -148,7 +148,15 @@ def get_operation_root_type(schema, operation):
148
148
)
149
149
150
150
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
+ """
152
160
for selection in selection_set .selections :
153
161
directives = selection .directives
154
162
@@ -160,10 +168,10 @@ def collect_fields(ctx, type, selection_set, fields, prev_fragment_names):
160
168
fields [name ].append (selection )
161
169
162
170
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 ):
164
172
continue
165
173
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 )
167
175
168
176
elif isinstance (selection , ast .FragmentSpread ):
169
177
frag_name = selection .name .value
@@ -176,10 +184,10 @@ def collect_fields(ctx, type, selection_set, fields, prev_fragment_names):
176
184
frag_directives = fragment .directives
177
185
if not fragment or not \
178
186
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 ):
180
188
continue
181
189
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 )
183
191
184
192
return fields
185
193
0 commit comments