Open atiberghien opened 2 years ago
Hi @atiberghien, thanks for the bug report, I'll edit the issue so that it is clear we need a management command for django 😊
For those who need a quick work around while #1658 is not released:
add this to a management/commmands/
directory of your choice
see the django documentation for more information.
from django.core.management import BaseCommand
from strawberry.printer import print_schema
from config.schema import schema # import your schema here
class Command(BaseCommand):
help = 'Exports the strawberry graphql schema'
def handle(self, *args, **options):
print(print_schema(schema))
call your file export_schema.py
after this you can use it like so: python manage.py export_schema
or python manage.py export_schema > schema.graphql
to save it to a file 👍
For those who need a quick work around while #1658 is not released:
add this to a
management/commmands/
directory of your choice see the django documentation for more information.from django.core.management import BaseCommand from strawberry.printer import print_schema from config.schema import schema # import your schema here class Command(BaseCommand): help = 'Exports the strawberry graphql schema' def handle(self, *args, **options): print(print_schema(schema))
call your file
export_schema.py
after this you can use it like so:
python manage.py export_schema
orpython manage.py export_schema > schema.graphql
to save it to a file 👍
@HelmutKarsten
I'm trying to use your workaround to generate my schema, but in my case, I'm using @strawberry.django.type
@strawberry.django.type(MyModel)
class My Entity:
id: auto
When I tried to export using that command appears error:
@strawberry.django.type(MyModel)
AttributeError: module 'strawberry' has no attribute 'django'
Do you know how can I fix this?
@fescobar can you try with import strawberry.django
at the top of your module?
@fescobar can you try with
import strawberry.django
at the top of your module?
It's working now, thank you for your quick response.
Looking at this as a good first issue. I see https://github.com/strawberry-graphql/strawberry/pull/1658 with a draft and https://github.com/strawberry-graphql/strawberry-graphql-django/pull/299 already added it to strawberry-graphql-django. Should this and https://github.com/strawberry-graphql/strawberry/pull/1658 be closed?
Otherwise should we give some message if django.core.exceptions.ImproperlyConfigured
is thrown to use the management command instead?
In addition to throwing an error, could this be corrected by adding the workaround as part of the documentation?
I'm working on issue 463 to add the documentation for the export_schema functionality. If we include the workaround in the docs it could clear up confusion from users.
When running
strawberry export-schema core.schema:schema
in a django project, we get this error:To fix this we should create a management command (so that the django settings are properly configured before exporting the schema).
The management command should have the same API as
export-schema
:)Upvote & Fund