Add dedicated django command for cypress schema

This commit is contained in:
Ramon Wenger 2020-03-16 10:05:29 +01:00
parent f222a6aa3b
commit 7b66d9b71b
2 changed files with 19 additions and 4 deletions

View File

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

View File

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