Skip to content

Commit

Permalink
Merge pull request #512 from kalekseev/schema-to-stdout
Browse files Browse the repository at this point in the history
Provide a way to dump schema to stdout.
  • Loading branch information
syrusakbary authored Sep 9, 2018
2 parents 3d493c3 + 85527e1 commit f76f38e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions graphene_django/management/commands/graphql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def add_arguments(self, parser):
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(
Expand Down Expand Up @@ -64,9 +64,12 @@ def handle(self, *args, **options):

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

0 comments on commit f76f38e

Please sign in to comment.