♻ Use TypedDocumentNode's instead of apollo-react-typescript codegen
💄 Add toast
24 lines
795 B
Python
24 lines
795 B
Python
from pathlib import Path
|
|
|
|
from django.core.management import BaseCommand, CommandParser
|
|
from strawberry.printer import print_schema
|
|
|
|
from bbssite.settings import BASE_DIR
|
|
from main.api.schema import schema as schema_symbol
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = " Write graphql schema to file or stdout"
|
|
|
|
def add_arguments(self, parser: CommandParser):
|
|
parser.add_argument("--filename", default='schema.graphql', help='`-` prints to stdout')
|
|
|
|
def handle(self, *args, filename=None, **options):
|
|
schema_output = print_schema(schema_symbol)
|
|
if filename != '-':
|
|
with Path(BASE_DIR, filename).open("w+") as fp:
|
|
fp.write(schema_output)
|
|
self.stdout.write(self.style.SUCCESS('OK'))
|
|
else:
|
|
print(schema_output)
|