<s> from . . language . printer import print_ast <EOL> from . . type . definition import ( GraphQLEnumType , GraphQLInputObjectType , <EOL> GraphQLInterfaceType , GraphQLObjectType , <EOL> GraphQLScalarType , GraphQLUnionType ) <EOL> from . ast_from_value import ast_from_value <EOL> def print_schema ( schema ) : <EOL> return _print_filtered_schema ( schema , _is_defined_type ) <EOL> def print_introspection_schema ( schema ) : <EOL> return _print_filtered_schema ( schema , _is_introspection_type ) <EOL> def _is_defined_type ( typename ) : <EOL> return not _is_introspection_type ( typename ) and not _is_builtin_scalar ( typename ) <EOL> def _is_introspection_type ( typename ) : <EOL> return typename . startswith ( '<STR_LIT>' ) <EOL> _builtin_scalars = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _is_builtin_scalar ( typename ) : <EOL> return typename in _builtin_scalars <EOL> def _print_filtered_schema ( schema , type_filter ) : <EOL> return '<STR_LIT>' . join ( <EOL> _print_type ( type ) <EOL> for typename , type in sorted ( schema . get_type_map ( ) . items ( ) ) <EOL> if type_filter ( typename ) <EOL> ) + '<STR_LIT:\n>' <EOL> def _print_type ( type ) : <EOL> if isinstance ( type , GraphQLScalarType ) : <EOL> return _print_scalar ( type ) <EOL> elif isinstance ( type , GraphQLObjectType ) : <EOL> return _print_object ( type ) <EOL> elif isinstance ( type , GraphQLInterfaceType ) : <EOL> return _print_interface ( type ) <EOL> elif isinstance ( type , GraphQLUnionType ) : <EOL> return _print_union ( type ) <EOL> elif isinstance ( type , GraphQLEnumType ) : <EOL> return _print_enum ( type ) <EOL> assert isinstance ( type , GraphQLInputObjectType ) <EOL> return _print_input_object ( type ) <EOL> def _print_scalar ( type ) : <EOL> return '<STR_LIT>' . format ( type . name ) <EOL> def _print_object ( type ) : <EOL> interfaces = type . get_interfaces ( ) <EOL> implemented_interfaces = '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( i . name for i in interfaces ) ) if interfaces else '<STR_LIT>' <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( type . name , implemented_interfaces , _print_fields ( type ) ) <EOL> def _print_interface ( type ) : <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( type . name , _print_fields ( type ) ) <EOL> def _print_union ( type ) : <EOL> return '<STR_LIT>' . format ( type . name , '<STR_LIT>' . join ( str ( t ) for t in type . get_possible_types ( ) ) ) <EOL> def _print_enum ( type ) : <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( type . name , '<STR_LIT:\n>' . join ( '<STR_LIT:U+0020>' + v . name for v in type . get_values ( ) ) ) <EOL> def _print_input_object ( type ) : <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( type . name , '<STR_LIT:\n>' . join ( '<STR_LIT:U+0020>' + _print_input_value ( field ) for field in type . get_fields ( ) . values ( ) ) ) <EOL> def _print_fields ( type ) : <EOL> return '<STR_LIT:\n>' . join ( '<STR_LIT>' . format ( f . name , _print_args ( f ) , f . type ) for f in type . get_fields ( ) . values ( ) ) <EOL> def _print_args ( field ) : <EOL> if not field . args : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( _print_input_value ( arg ) for arg in field . args ) ) <EOL> def _print_input_value ( arg ) : <EOL> if arg . default_value is not None : <EOL> default_value = '<STR_LIT>' + print_ast ( ast_from_value ( arg . default_value , arg . type ) ) <EOL> else : <EOL> default_value = '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( arg . name , arg . type , default_value ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] </s>
