mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 17:47:12 +03:00
add indent support for graphql_schema command
This commit is contained in:
parent
60bcc0beef
commit
62d3eb911a
|
@ -27,6 +27,13 @@ if LT_DJANGO_1_8:
|
||||||
default='',
|
default='',
|
||||||
help='Output file (default: schema.json)'
|
help='Output file (default: schema.json)'
|
||||||
),
|
),
|
||||||
|
make_option(
|
||||||
|
'--indent',
|
||||||
|
type=int,
|
||||||
|
dest='indent',
|
||||||
|
default=None,
|
||||||
|
help='Output file indent (default: None)'
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
class CommandArguments(BaseCommand):
|
class CommandArguments(BaseCommand):
|
||||||
|
@ -46,14 +53,21 @@ else:
|
||||||
default=graphene_settings.SCHEMA_OUTPUT,
|
default=graphene_settings.SCHEMA_OUTPUT,
|
||||||
help='Output file (default: schema.json)')
|
help='Output file (default: schema.json)')
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--indent',
|
||||||
|
type=int,
|
||||||
|
dest='indent',
|
||||||
|
default=graphene_settings.SCHEMA_INDENT,
|
||||||
|
help='Output file indent (default: None)')
|
||||||
|
|
||||||
|
|
||||||
class Command(CommandArguments):
|
class Command(CommandArguments):
|
||||||
help = 'Dump Graphene schema JSON to file'
|
help = 'Dump Graphene schema JSON to file'
|
||||||
can_import_settings = True
|
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:
|
with open(out, 'w') as outfile:
|
||||||
json.dump(schema_dict, outfile)
|
json.dump(schema_dict, outfile, indent=indent)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
options_schema = options.get('schema')
|
options_schema = options.get('schema')
|
||||||
|
@ -74,8 +88,9 @@ class Command(CommandArguments):
|
||||||
if not schema:
|
if not schema:
|
||||||
raise CommandError('Specify schema on GRAPHENE.SCHEMA setting or by using --schema')
|
raise CommandError('Specify schema on GRAPHENE.SCHEMA setting or by using --schema')
|
||||||
|
|
||||||
|
indent = options.get('indent')
|
||||||
schema_dict = {'data': schema.introspect()}
|
schema_dict = {'data': schema.introspect()}
|
||||||
self.save_file(out, schema_dict)
|
self.save_file(out, schema_dict, indent)
|
||||||
|
|
||||||
style = getattr(self, 'style', None)
|
style = getattr(self, 'style', None)
|
||||||
success = getattr(style, 'SUCCESS', lambda x: x)
|
success = getattr(style, 'SUCCESS', lambda x: x)
|
||||||
|
|
|
@ -28,6 +28,7 @@ except ImportError:
|
||||||
DEFAULTS = {
|
DEFAULTS = {
|
||||||
'SCHEMA': None,
|
'SCHEMA': None,
|
||||||
'SCHEMA_OUTPUT': 'schema.json',
|
'SCHEMA_OUTPUT': 'schema.json',
|
||||||
|
'SCHEMA_INDENT': None,
|
||||||
'MIDDLEWARE': (),
|
'MIDDLEWARE': (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user