Merge pull request #512 from kalekseev/schema-to-stdout

Provide a way to dump schema to stdout.
This commit is contained in:
Syrus Akbary 2018-09-09 22:49:53 +02:00 committed by GitHub
commit f76f38ef30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))