Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit d6c0df5

Browse files
Fix bug involving cascading suppression error (#992)
* Fix bug involving cascading suppression error * Add test
1 parent 33cc5e8 commit d6c0df5

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

graphql_compiler/schema_transformation/rename_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,9 @@ def enter_field_definition(
11161116
# Therefore, we don't need to explicitly suppress the field as well and this should not
11171117
# raise errors.
11181118
return IDLE
1119+
if self.field_renamings.get(self.current_type, {}).get(field_name, {field_name}) == set():
1120+
# Field was also suppressed so this should not raise errors.
1121+
return IDLE
11191122
if self.current_type not in self.fields_to_suppress:
11201123
self.fields_to_suppress[self.current_type] = {}
11211124
self.fields_to_suppress[self.current_type][field_name] = field_type

graphql_compiler/tests/schema_transformation_tests/test_rename_schema.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,45 @@ def test_field_still_depends_on_suppressed_type(self) -> None:
11401140
parse(ISS.multiple_fields_schema), {"Dog": None}, {}
11411141
) # The type named Human contains a field of type Dog.
11421142

1143+
def test_suppress_field_prevent_cascading_suppression_error(self) -> None:
1144+
renamed_schema = rename_schema(
1145+
parse(ISS.multiple_fields_schema), {"Dog": None}, {"Human": {"pet": set()}}
1146+
)
1147+
renamed_schema_string = dedent(
1148+
"""\
1149+
schema {
1150+
query: SchemaQuery
1151+
}
1152+
1153+
directive @output(
1154+
\"\"\"What to designate the output field generated from this property field.\"\"\"
1155+
out_name: String!
1156+
) on FIELD
1157+
1158+
type Human {
1159+
id: String
1160+
name: String
1161+
age: Int
1162+
droid: Droid
1163+
}
1164+
1165+
type Droid {
1166+
id: String
1167+
model: String
1168+
}
1169+
1170+
type SchemaQuery {
1171+
Human: Human
1172+
Droid: Droid
1173+
}
1174+
"""
1175+
)
1176+
compare_schema_texts_order_independently(
1177+
self, renamed_schema_string, print_ast(renamed_schema.schema_ast)
1178+
)
1179+
self.assertEqual({}, renamed_schema.reverse_name_map)
1180+
self.assertEqual({}, renamed_schema.reverse_field_name_map)
1181+
11431182
def test_field_of_suppressed_type_in_suppressed_type(self) -> None:
11441183
# The schema contains an object type that contains a field of the type Human. Normally,
11451184
# suppressing the type named Human would cause a CascadingSuppressionError because the

0 commit comments

Comments
 (0)