Skip to content

Commit ecc5e13

Browse files
committed
Minor changes to match upstream code modernization
Replicates graphql/graphql-js@564757f
1 parent 42cabdb commit ecc5e13

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/graphql/language/visitor.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,20 @@ def visit(
218218
node: Any = parent
219219
parent = ancestors_pop() if ancestors else None
220220
if is_edited:
221-
node = node[:] if in_array else copy(node)
222-
edit_offset = 0
223-
for edit_key, edit_value in edits:
224221
if in_array:
225-
edit_key -= edit_offset
226-
if in_array and (edit_value is REMOVE or edit_value is Ellipsis):
227-
node.pop(edit_key)
228-
edit_offset += 1
229-
elif isinstance(node, list):
230-
node[edit_key] = edit_value
222+
node = node[:]
223+
edit_offset = 0
224+
for edit_key, edit_value in edits:
225+
array_key = edit_key - edit_offset
226+
if edit_value is REMOVE or edit_value is Ellipsis:
227+
node.pop(array_key)
228+
edit_offset += 1
229+
else:
230+
node[array_key] = edit_value
231231
else:
232-
setattr(node, edit_key, edit_value)
233-
232+
node = copy(node)
233+
for edit_key, edit_value in edits:
234+
setattr(node, edit_key, edit_value)
234235
idx = stack.idx
235236
keys = stack.keys
236237
edits = stack.edits

src/graphql/utilities/strip_ignored_characters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ def dedent_block_string(block_str: str) -> str:
103103
if get_block_string_indentation(body) > 0:
104104
body = "\n" + body
105105

106-
last_char = body[-1:]
107-
has_trailing_quote = last_char == '"' and body[-4:] != '\\"""'
108-
if has_trailing_quote or last_char == "\\":
106+
has_trailing_quote = body.endswith('"') and not body.endswith('\\"""')
107+
if has_trailing_quote or body.endswith("\\"):
109108
body += "\n"
110109

111110
return '"""' + body + '"""'

src/graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def collect_conflicts_between_fields_and_fragment(
229229
if not fragment:
230230
return None
231231

232-
field_map2, fragment_names2 = get_referenced_fields_and_fragment_names(
232+
field_map2, referenced_fragment_names = get_referenced_fields_and_fragment_names(
233233
context, cached_fields_and_fragment_names, fragment
234234
)
235235

@@ -251,15 +251,15 @@ def collect_conflicts_between_fields_and_fragment(
251251

252252
# (E) Then collect any conflicts between the provided collection of fields and any
253253
# fragment names found in the given fragment.
254-
for fragment_name2 in fragment_names2:
254+
for referenced_fragment_name in referenced_fragment_names:
255255
collect_conflicts_between_fields_and_fragment(
256256
context,
257257
conflicts,
258258
cached_fields_and_fragment_names,
259259
compared_fragment_pairs,
260260
are_mutually_exclusive,
261261
field_map,
262-
fragment_name2,
262+
referenced_fragment_name,
263263
)
264264

265265

@@ -293,11 +293,11 @@ def collect_conflicts_between_fragments(
293293
if not fragment1 or not fragment2:
294294
return None
295295

296-
field_map1, fragment_names1 = get_referenced_fields_and_fragment_names(
296+
field_map1, referenced_fragment_names1 = get_referenced_fields_and_fragment_names(
297297
context, cached_fields_and_fragment_names, fragment1
298298
)
299299

300-
field_map2, fragment_names2 = get_referenced_fields_and_fragment_names(
300+
field_map2, referenced_fragment_names2 = get_referenced_fields_and_fragment_names(
301301
context, cached_fields_and_fragment_names, fragment2
302302
)
303303

@@ -315,27 +315,27 @@ def collect_conflicts_between_fragments(
315315

316316
# (G) Then collect conflicts between the first fragment and any nested fragments
317317
# spread in the second fragment.
318-
for nested_fragment_name2 in fragment_names2:
318+
for referenced_fragment_name2 in referenced_fragment_names2:
319319
collect_conflicts_between_fragments(
320320
context,
321321
conflicts,
322322
cached_fields_and_fragment_names,
323323
compared_fragment_pairs,
324324
are_mutually_exclusive,
325325
fragment_name1,
326-
nested_fragment_name2,
326+
referenced_fragment_name2,
327327
)
328328

329329
# (G) Then collect conflicts between the second fragment and any nested fragments
330330
# spread in the first fragment.
331-
for nested_fragment_name1 in fragment_names1:
331+
for referenced_fragment_name1 in referenced_fragment_names1:
332332
collect_conflicts_between_fragments(
333333
context,
334334
conflicts,
335335
cached_fields_and_fragment_names,
336336
compared_fragment_pairs,
337337
are_mutually_exclusive,
338-
nested_fragment_name1,
338+
referenced_fragment_name1,
339339
fragment_name2,
340340
)
341341

0 commit comments

Comments
 (0)