From dea4719fd1462a9cc918f7ba1e5b973ef2a0538d Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Mon, 22 Feb 2021 17:14:10 +0100 Subject: [PATCH] Add django command to generate a GraphQL SDL file --- .../commands/export_schema_graphql.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 server/core/management/commands/export_schema_graphql.py diff --git a/server/core/management/commands/export_schema_graphql.py b/server/core/management/commands/export_schema_graphql.py new file mode 100644 index 00000000..916bc051 --- /dev/null +++ b/server/core/management/commands/export_schema_graphql.py @@ -0,0 +1,21 @@ +from django.core.management import BaseCommand +from django.core.management import call_command +from django.conf import settings +import json +import os + + +class Command(BaseCommand): + def handle(self, *args, **options): + from api.schema import schema + from api.schema_public import schema as schema_public + + schema_path = os.path.join(settings.BASE_DIR, '..', 'schema.graphql') + public_schema_path = os.path.join(settings.BASE_DIR, '..', 'schema_public.graphql') + + with open(schema_path, 'w') as o: + o.write(str(schema)) + + with open(public_schema_path, 'w') as o: + o.write(str(schema_public)) +