Skip to content

Commit f76f38e

Browse files
authored
Merge pull request #512 from kalekseev/schema-to-stdout
Provide a way to dump schema to stdout.
2 parents 3d493c3 + 85527e1 commit f76f38e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

graphene_django/management/commands/graphql_schema.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def add_arguments(self, parser):
2121
type=str,
2222
dest="out",
2323
default=graphene_settings.SCHEMA_OUTPUT,
24-
help="Output file (default: schema.json)",
24+
help="Output file, --out=- prints to stdout (default: schema.json)",
2525
)
2626

2727
parser.add_argument(
@@ -64,9 +64,12 @@ def handle(self, *args, **options):
6464

6565
indent = options.get("indent")
6666
schema_dict = {"data": schema.introspect()}
67-
self.save_file(out, schema_dict, indent)
67+
if out == '-':
68+
self.stdout.write(json.dumps(schema_dict, indent=indent))
69+
else:
70+
self.save_file(out, schema_dict, indent)
6871

69-
style = getattr(self, "style", None)
70-
success = getattr(style, "SUCCESS", lambda x: x)
72+
style = getattr(self, "style", None)
73+
success = getattr(style, "SUCCESS", lambda x: x)
7174

72-
self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out))
75+
self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out))

0 commit comments

Comments
 (0)