diff --git a/graphene/contrib/django/management/commands/graphql_schema.py b/graphene/contrib/django/management/commands/graphql_schema.py index 07b802d4..2047739d 100644 --- a/graphene/contrib/django/management/commands/graphql_schema.py +++ b/graphene/contrib/django/management/commands/graphql_schema.py @@ -25,6 +25,13 @@ if LT_DJANGO_1_8: default='', help='Output file (default: schema.json)' ), + make_option( + '--indent', + type=int, + dest='indent', + default=None, + help='Number of indentation spaces to use in the output', + ), ) else: class CommandArguments(BaseCommand): @@ -45,26 +52,34 @@ else: default=getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json'), help='Output file (default: schema.json)') + parser.add_argument( + '--indent', + type=int, + dest='indent', + default=getattr(settings, 'GRAPHENE_SCHEMA_INDENT', None), + help='Number of indentation spaces to use in the output') + class Command(CommandArguments): help = 'Dump Graphene schema JSON to file' can_import_settings = True - def save_file(self, out, schema_dict): + def save_file(self, out, schema_dict, indent): with open(out, 'w') as outfile: - json.dump(schema_dict, outfile) + json.dump(schema_dict, outfile, indent=indent) def handle(self, *args, **options): from django.conf import settings schema = options.get('schema') or getattr(settings, 'GRAPHENE_SCHEMA', '') out = options.get('out') or getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json') + indent = options.get('indent') or getattr(settings, 'GRAPHENE_SCHEMA_INDENT', None) if schema == '': raise CommandError('Specify schema on GRAPHENE_SCHEMA setting or by using --schema') i = importlib.import_module(schema) schema_dict = {'data': i.schema.introspect()} - self.save_file(out, schema_dict) + self.save_file(out, schema_dict, indent) style = getattr(self, 'style', None) SUCCESS = getattr(style, 'SUCCESS', lambda x: x)