@@ -380,8 +380,7 @@ def get_operation_types(
380380 return {
381381 operation_type .operation : get_named_type (operation_type .type )
382382 for node in nodes
383- if node .operation_types
384- for operation_type in node .operation_types
383+ for operation_type in node .operation_types or []
385384 }
386385
387386 # noinspection PyShadowingNames
@@ -426,38 +425,34 @@ def build_field_map(
426425 ) -> GraphQLFieldMap :
427426 field_map : GraphQLFieldMap = {}
428427 for node in nodes :
429- if node .fields :
430- for field in node .fields :
431- # Note: While this could make assertions to get the correctly typed
432- # value, that would throw immediately while type system validation
433- # with validate_schema() will produce more actionable results.
434- field_map [field .name .value ] = GraphQLField (
435- type_ = cast (GraphQLOutputType , get_wrapped_type (field .type )),
436- description = field .description .value
437- if field .description
438- else None ,
439- args = build_argument_map (field .arguments ),
440- deprecation_reason = get_deprecation_reason (field ),
441- ast_node = field ,
442- )
428+ for field in node .fields or []:
429+ # Note: While this could make assertions to get the correctly typed
430+ # value, that would throw immediately while type system validation
431+ # with validate_schema() will produce more actionable results.
432+ field_map [field .name .value ] = GraphQLField (
433+ type_ = cast (GraphQLOutputType , get_wrapped_type (field .type )),
434+ description = field .description .value if field .description else None ,
435+ args = build_argument_map (field .arguments ),
436+ deprecation_reason = get_deprecation_reason (field ),
437+ ast_node = field ,
438+ )
443439 return field_map
444440
445441 def build_argument_map (
446442 args : Optional [Collection [InputValueDefinitionNode ]],
447443 ) -> GraphQLArgumentMap :
448444 arg_map : GraphQLArgumentMap = {}
449- if args :
450- for arg in args :
451- # Note: While this could make assertions to get the correctly typed
452- # value, that would throw immediately while type system validation
453- # with validate_schema() will produce more actionable results.
454- type_ = cast (GraphQLInputType , get_wrapped_type (arg .type ))
455- arg_map [arg .name .value ] = GraphQLArgument (
456- type_ = type_ ,
457- description = arg .description .value if arg .description else None ,
458- default_value = value_from_ast (arg .default_value , type_ ),
459- ast_node = arg ,
460- )
445+ for arg in args or []:
446+ # Note: While this could make assertions to get the correctly typed
447+ # value, that would throw immediately while type system validation
448+ # with validate_schema() will produce more actionable results.
449+ type_ = cast (GraphQLInputType , get_wrapped_type (arg .type ))
450+ arg_map [arg .name .value ] = GraphQLArgument (
451+ type_ = type_ ,
452+ description = arg .description .value if arg .description else None ,
453+ default_value = value_from_ast (arg .default_value , type_ ),
454+ ast_node = arg ,
455+ )
461456 return arg_map
462457
463458 def build_input_field_map (
@@ -467,39 +462,33 @@ def build_input_field_map(
467462 ) -> GraphQLInputFieldMap :
468463 input_field_map : GraphQLInputFieldMap = {}
469464 for node in nodes :
470- if node .fields :
471- for field in node .fields :
472- # Note: While this could make assertions to get the correctly typed
473- # value, that would throw immediately while type system validation
474- # with validate_schema() will produce more actionable results.
475- type_ = cast (GraphQLInputType , get_wrapped_type (field .type ))
476- input_field_map [field .name .value ] = GraphQLInputField (
477- type_ = type_ ,
478- description = field .description .value
479- if field .description
480- else None ,
481- default_value = value_from_ast (field .default_value , type_ ),
482- ast_node = field ,
483- )
465+ for field in node .fields or []:
466+ # Note: While this could make assertions to get the correctly typed
467+ # value, that would throw immediately while type system validation
468+ # with validate_schema() will produce more actionable results.
469+ type_ = cast (GraphQLInputType , get_wrapped_type (field .type ))
470+ input_field_map [field .name .value ] = GraphQLInputField (
471+ type_ = type_ ,
472+ description = field .description .value if field .description else None ,
473+ default_value = value_from_ast (field .default_value , type_ ),
474+ ast_node = field ,
475+ )
484476 return input_field_map
485477
486478 def build_enum_value_map (
487479 nodes : Collection [Union [EnumTypeDefinitionNode , EnumTypeExtensionNode ]]
488480 ) -> GraphQLEnumValueMap :
489481 enum_value_map : GraphQLEnumValueMap = {}
490482 for node in nodes :
491- if node .values :
492- for value in node .values :
493- # Note: While this could make assertions to get the correctly typed
494- # value, that would throw immediately while type system validation
495- # with validate_schema() will produce more actionable results.
496- enum_value_map [value .name .value ] = GraphQLEnumValue (
497- description = value .description .value
498- if value .description
499- else None ,
500- deprecation_reason = get_deprecation_reason (value ),
501- ast_node = value ,
502- )
483+ for value in node .values or []:
484+ # Note: While this could make assertions to get the correctly typed
485+ # value, that would throw immediately while type system validation
486+ # with validate_schema() will produce more actionable results.
487+ enum_value_map [value .name .value ] = GraphQLEnumValue (
488+ description = value .description .value if value .description else None ,
489+ deprecation_reason = get_deprecation_reason (value ),
490+ ast_node = value ,
491+ )
503492 return enum_value_map
504493
505494 def build_interfaces (
@@ -514,25 +503,23 @@ def build_interfaces(
514503 ) -> List [GraphQLInterfaceType ]:
515504 interfaces : List [GraphQLInterfaceType ] = []
516505 for node in nodes :
517- if node .interfaces :
518- for type_ in node .interfaces :
519- # Note: While this could make assertions to get the correctly typed
520- # value, that would throw immediately while type system validation
521- # with validate_schema() will produce more actionable results.
522- interfaces .append (cast (GraphQLInterfaceType , get_named_type (type_ )))
506+ for type_ in node .interfaces or []:
507+ # Note: While this could make assertions to get the correctly typed
508+ # value, that would throw immediately while type system validation
509+ # with validate_schema() will produce more actionable results.
510+ interfaces .append (cast (GraphQLInterfaceType , get_named_type (type_ )))
523511 return interfaces
524512
525513 def build_union_types (
526514 nodes : Collection [Union [UnionTypeDefinitionNode , UnionTypeExtensionNode ]],
527515 ) -> List [GraphQLObjectType ]:
528516 types : List [GraphQLObjectType ] = []
529517 for node in nodes :
530- if node .types :
531- for type_ in node .types :
532- # Note: While this could make assertions to get the correctly typed
533- # value, that would throw immediately while type system validation
534- # with validate_schema() will produce more actionable results.
535- types .append (cast (GraphQLObjectType , get_named_type (type_ )))
518+ for type_ in node .types or []:
519+ # Note: While this could make assertions to get the correctly typed
520+ # value, that would throw immediately while type system validation
521+ # with validate_schema() will produce more actionable results.
522+ types .append (cast (GraphQLObjectType , get_named_type (type_ )))
536523 return types
537524
538525 def build_object_type (ast_node : ObjectTypeDefinitionNode ) -> GraphQLObjectType :
0 commit comments