Add dedicated django command for cypress schema
This commit is contained in:
parent
f222a6aa3b
commit
7b66d9b71b
|
|
@ -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
|
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.
|
|
||||||
|
|
|
||||||
|
|
@ -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))
|
||||||
Loading…
Reference in New Issue