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

Commit 8a3ffe2

Browse files
Move builtin scalar renaming check to code rather than separate validation step (#994)
* Move builtin scalar renaming check to code rather than separate validation step * Address comment
1 parent 34c968b commit 8a3ffe2

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

graphql_compiler/schema_transformation/rename_schema.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _validate_renamings(
283283
type implementing an interface
284284
"""
285285
_ensure_no_cascading_type_suppressions(schema_ast, type_renamings, field_renamings, query_type)
286-
_ensure_no_unsupported_operations(schema_ast, type_renamings)
286+
_ensure_no_unsupported_suppressions(schema_ast, type_renamings)
287287

288288

289289
def _ensure_no_cascading_type_suppressions(
@@ -339,29 +339,6 @@ def _ensure_no_cascading_type_suppressions(
339339
raise CascadingSuppressionError("\n".join(error_message_components))
340340

341341

342-
def _ensure_no_unsupported_operations(
343-
schema_ast: DocumentNode,
344-
type_renamings: Mapping[str, Optional[str]],
345-
) -> None:
346-
"""Check for unsupported type renaming or suppression operations."""
347-
_ensure_no_unsupported_scalar_operations(type_renamings)
348-
_ensure_no_unsupported_suppressions(schema_ast, type_renamings)
349-
350-
351-
def _ensure_no_unsupported_scalar_operations(
352-
type_renamings: Mapping[str, Optional[str]],
353-
) -> None:
354-
"""Check for unsupported scalar operations."""
355-
unsupported_scalar_operations = {
356-
scalar_name for scalar_name in builtin_scalar_type_names if scalar_name in type_renamings
357-
}
358-
if unsupported_scalar_operations:
359-
raise NotImplementedError(
360-
f"Type_renamings contained renamings for the following built-in scalar types: "
361-
f"{unsupported_scalar_operations}. To fix this, remove them from type_renamings."
362-
)
363-
364-
365342
def _ensure_no_unsupported_suppressions(
366343
schema_ast: DocumentNode, type_renamings: Mapping[str, Optional[str]]
367344
) -> None:
@@ -489,6 +466,12 @@ def _rename_and_suppress_types_and_fields(
489466
f"they exist for the following types and should be removed: "
490467
f"{visitor.types_involving_interfaces_with_field_renamings}"
491468
)
469+
if visitor.illegal_builtin_scalar_renamings:
470+
raise NotImplementedError(
471+
f"Type_renamings contained renamings for the following built-in scalar types: "
472+
f"{visitor.illegal_builtin_scalar_renamings}. To fix this, remove them from "
473+
f"type_renamings."
474+
)
492475
for type_name in visitor.suppressed_type_names:
493476
if type_name not in type_renamings:
494477
raise AssertionError(
@@ -642,6 +625,11 @@ class RenameSchemaTypesVisitor(Visitor):
642625
# "Foo" to "String"
643626
type_renamed_to_builtin_scalar_conflicts: Dict[str, str]
644627

628+
# Collects naming errors that arise from attempting to rename a builtin scalar. If
629+
# type_renamings["String"] == "Foo" schema, illegal_builtin_scalar_renamings will contain
630+
# "String"
631+
illegal_builtin_scalar_renamings: Set[str]
632+
645633
# reverse_name_map maps renamed type name to original type name, containing all non-suppressed
646634
# types, including those that were unchanged. Must contain unchanged names to prevent type
647635
# renaming conflicts and raise SchemaRenameNameConflictError when they arise
@@ -717,6 +705,11 @@ def __init__(
717705
self.reverse_name_map = {}
718706
self.type_name_conflicts = {}
719707
self.type_renamed_to_builtin_scalar_conflicts = {}
708+
self.illegal_builtin_scalar_renamings = {
709+
scalar_name
710+
for scalar_name in builtin_scalar_type_names
711+
if scalar_name in type_renamings
712+
}
720713
self.invalid_type_names = {}
721714
self.query_type = query_type
722715
self.suppressed_type_names = set()
@@ -754,6 +747,7 @@ def _rename_or_suppress_or_ignore_name_and_add_to_record(
754747
return IDLE
755748

756749
desired_type_name = self.type_renamings.get(type_name, type_name) # Default use original
750+
757751
if desired_type_name is None:
758752
# Suppress the type
759753
self.suppressed_type_names.add(type_name)

0 commit comments

Comments
 (0)