diff --git a/README.md b/README.md index 38189c9f..77bbe261 100644 --- a/README.md +++ b/README.md @@ -190,8 +190,5 @@ There is a schema.json in the fixtures folder. For now it has been generated onc To generate a new schema, use the management command ``` -python manage.py graphql_schema --schema api.schema.schema --out schema.json --indent 4 +python manage.py export_schema_for_cypress ``` - -Then, remove the `data` property from the generated `schema.json`, so the `__schema` property is on the top level. -Also remove the two objects with `"name": "__debug"` from the JSON file. diff --git a/server/core/management/commands/export_schema_for_cypress.py b/server/core/management/commands/export_schema_for_cypress.py new file mode 100644 index 00000000..095b08e2 --- /dev/null +++ b/server/core/management/commands/export_schema_for_cypress.py @@ -0,0 +1,18 @@ +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): + filename = 'schema.json' + cypress_path = os.path.join(settings.BASE_DIR, '..', 'client', 'cypress', 'fixtures', filename) + call_command('graphql_schema', schema='api.schema.schema', out=filename, indent=4) + with open(filename) as f: + initial_json = json.loads(f.read()) + + data = initial_json['data'] + with open(cypress_path, 'w') as o: + o.write(json.dumps(data))