def format_config_for_graphql(config):
def _format_config_subdict(config, current_indent=<NUM_LIT:0>):<EOL><INDENT>check.dict_param(config, '<STR_LIT>', key_type=str)<EOL>printer = IndentingStringIoPrinter(indent_level=<NUM_LIT:2>, current_indent=current_indent)<EOL>printer.line('<STR_LIT:{>')<EOL>n_elements = len(config)<EOL>for i, key in enumerate(sorted(config, key=lambda x: x[<NUM_LIT:0>])):<EOL><INDENT>value = config[key]<EOL>with printer.with_indent():<EOL><INDENT>formatted_value = (<EOL>_format_config_item(value, current_indent=printer.current_indent)<EOL>.lstrip('<STR_LIT:U+0020>')<EOL>.rstrip('<STR_LIT:\n>')<EOL>)<EOL>printer.line(<EOL>'<STR_LIT>'.format(<EOL>key=key,<EOL>formatted_value=formatted_value,<EOL>comma='<STR_LIT:U+002C>' if i != n_elements - <NUM_LIT:1> else '<STR_LIT>',<EOL>)<EOL>)<EOL><DEDENT><DEDENT>printer.line('<STR_LIT:}>')<EOL>return printer.read()<EOL><DEDENT>def _format_config_sublist(config, current_indent=<NUM_LIT:0>):<EOL><INDENT>printer = IndentingStringIoPrinter(indent_level=<NUM_LIT:2>, current_indent=current_indent)<EOL>printer.line('<STR_LIT:[>')<EOL>n_elements = len(config)<EOL>for i, value in enumerate(config):<EOL><INDENT>with printer.with_indent():<EOL><INDENT>formatted_value = (<EOL>_format_config_item(value, current_indent=printer.current_indent)<EOL>.lstrip('<STR_LIT:U+0020>')<EOL>.rstrip('<STR_LIT:\n>')<EOL>)<EOL>printer.line(<EOL>'<STR_LIT>'.format(<EOL>formatted_value=formatted_value, comma='<STR_LIT:U+002C>' if i != n_elements - <NUM_LIT:1> else '<STR_LIT>'<EOL>)<EOL>)<EOL><DEDENT><DEDENT>printer.line('<STR_LIT:]>')<EOL>return printer.read()<EOL><DEDENT>def _format_config_item(config, current_indent=<NUM_LIT:0>):<EOL><INDENT>printer = IndentingStringIoPrinter(indent_level=<NUM_LIT:2>, current_indent=current_indent)<EOL>if isinstance(config, dict):<EOL><INDENT>return _format_config_subdict(config, printer.current_indent)<EOL><DEDENT>elif isinstance(config, list):<EOL><INDENT>return _format_config_sublist(config, printer.current_indent)<EOL><DEDENT>elif isinstance(config, bool):<EOL><INDENT>return repr(config).lower()<EOL><DEDENT>else:<EOL><INDENT>return repr(config).replace('<STR_LIT>', '<STR_LIT:">')<EOL><DEDENT><DEDENT>check.dict_param(config, '<STR_LIT>', key_type=str)<EOL>if not isinstance(config, dict):<EOL><INDENT>check.failed('<STR_LIT>'.format(item=repr(config)))<EOL><DEDENT>return _format_config_subdict(config)<EOL>
This recursive descent thing formats a config dict for GraphQL.