From 85527e1f94a659eb14094d8c343c43f8fcf67c07 Mon Sep 17 00:00:00 2001 From: Konstantin Alekseev Date: Sat, 8 Sep 2018 15:33:30 +0300 Subject: [PATCH] Provide a way to dump schema to stdout. --- .../management/commands/graphql_schema.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/graphene_django/management/commands/graphql_schema.py b/graphene_django/management/commands/graphql_schema.py index 099af5d..4e526ec 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -21,7 +21,7 @@ class CommandArguments(BaseCommand): type=str, dest="out", default=graphene_settings.SCHEMA_OUTPUT, - help="Output file (default: schema.json)", + help="Output file, --out=- prints to stdout (default: schema.json)", ) parser.add_argument( @@ -64,9 +64,12 @@ class Command(CommandArguments): indent = options.get("indent") schema_dict = {"data": schema.introspect()} - self.save_file(out, schema_dict, indent) + if out == '-': + self.stdout.write(json.dumps(schema_dict, indent=indent)) + else: + self.save_file(out, schema_dict, indent) - style = getattr(self, "style", None) - success = getattr(style, "SUCCESS", lambda x: x) + style = getattr(self, "style", None) + success = getattr(style, "SUCCESS", lambda x: x) - self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out)) + self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out))