Skip to content

Commit ce06e95

Browse files
authored
Merge pull request #25 from stegben/command-indent
Command indent
2 parents efc8fd6 + cf7d8ff commit ce06e95

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

examples/cookbook/cookbook/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@
130130
# https://docs.djangoproject.com/en/1.9/howto/static-files/
131131

132132
STATIC_URL = '/static/'
133+
134+
GRAPHENE = {
135+
'SCHEMA': 'cookbook.schema.schema',
136+
'SCHEMA_INDENT': 2,
137+
}

graphene_django/management/commands/graphql_schema.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class CommandArguments(BaseCommand):
2727
default='',
2828
help='Output file (default: schema.json)'
2929
),
30+
make_option(
31+
'--indent',
32+
type=int,
33+
dest='indent',
34+
default=None,
35+
help='Output file indent (default: None)'
36+
),
3037
)
3138
else:
3239
class CommandArguments(BaseCommand):
@@ -46,14 +53,21 @@ def add_arguments(self, parser):
4653
default=graphene_settings.SCHEMA_OUTPUT,
4754
help='Output file (default: schema.json)')
4855

56+
parser.add_argument(
57+
'--indent',
58+
type=int,
59+
dest='indent',
60+
default=graphene_settings.SCHEMA_INDENT,
61+
help='Output file indent (default: None)')
62+
4963

5064
class Command(CommandArguments):
5165
help = 'Dump Graphene schema JSON to file'
5266
can_import_settings = True
5367

54-
def save_file(self, out, schema_dict):
68+
def save_file(self, out, schema_dict, indent):
5569
with open(out, 'w') as outfile:
56-
json.dump(schema_dict, outfile)
70+
json.dump(schema_dict, outfile, indent=indent)
5771

5872
def handle(self, *args, **options):
5973
options_schema = options.get('schema')
@@ -74,8 +88,9 @@ def handle(self, *args, **options):
7488
if not schema:
7589
raise CommandError('Specify schema on GRAPHENE.SCHEMA setting or by using --schema')
7690

91+
indent = options.get('indent')
7792
schema_dict = {'data': schema.introspect()}
78-
self.save_file(out, schema_dict)
93+
self.save_file(out, schema_dict, indent)
7994

8095
style = getattr(self, 'style', None)
8196
success = getattr(style, 'SUCCESS', lambda x: x)

graphene_django/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DEFAULTS = {
2929
'SCHEMA': None,
3030
'SCHEMA_OUTPUT': 'schema.json',
31+
'SCHEMA_INDENT': None,
3132
'MIDDLEWARE': (),
3233
}
3334

0 commit comments

Comments
 (0)