Handle possible None enum value
default_value can be None in InputValueDefinitionNode (and any other subclass
of DefinitionNode default_value property), so it should be handled at all times.
Refactored the enum_values_in_input_type and enum_values_in_field_args to use
the same helper function, so they can consistently handle the same edge case.
@@ -159,16 +159,7 @@ def enum_values_in_input_type(
type_: GraphQLInputObjectType,
field_name,
) -> Generator[InputFieldWithKeys, None, None]:
- for input_name, field in type_.fields.items():
- resolved_type = resolve_null_type(field.type)
- if isinstance(resolved_type, GraphQLEnumType):
- yield field_name, input_name, field, None
-
- if isinstance(resolved_type, GraphQLInputObjectType):
- if field.ast_node is not None:
- routes = get_enum_keys_from_ast(field.ast_node)
- for route in routes:
- yield field_name, input_name, field, route
+ yield from _get_field_with_keys(field_name, type_.fields.items())
def enum_values_in_field_args(
@@ -183,16 +174,20 @@ def enum_values_in_field_args(
)
]
- for arg_name, arg in args:
- type_ = resolve_null_type(arg.type)
- if isinstance(type_, GraphQLEnumType):
- yield field_name, arg_name, arg, None
+ yield from _get_field_with_keys(field_name, args)
- if isinstance(type_, GraphQLInputObjectType):
- if arg.ast_node is not None and arg.ast_node.default_value is not None:
- routes = get_enum_keys_from_ast(arg.ast_node)
+
+def _get_field_with_keys(field_name, fields):
+ for input_name, field in fields:
+ resolved_type = resolve_null_type(field.type)
+ if isinstance(resolved_type, GraphQLEnumType):
+ yield field_name, input_name, field, None
+
+ if isinstance(resolved_type, GraphQLInputObjectType):
+ if field.ast_node is not None and field.ast_node.default_value is not None:
+ routes = get_enum_keys_from_ast(field.ast_node)
for route in routes:
- yield field_name, arg_name, arg, route
+ yield field_name, input_name, field, route
def get_enum_keys_from_ast(ast_node: InputValueDefinitionNode) -> List[List["str"]]:
