Codegen django command for strawberry-django for rapid schema boilerplate generation from given models
pip3 install strawberry_jamor using uv
uv pip install strawberry_jamAdd 'strawberry_jam' to your project's settings.py.
INSTALLED_APPS = [
# ... other apps
'strawberry_jam',
]Configure strawberry django to handle GlobalIds automatically.
STRAWBERRY_DJANGO = {
"MAP_AUTO_ID_AS_GLOBAL_ID": True
}python3 manage.py configure-schema <app_label.ModelName1> <app_label.ModelName2> <app_label.ModelNameN> -in <my_graphql_app_label> -fl <flavor_name>- list of models in form of
app_label.ModelName --in-app,-in: theapp_labelwhere the schema modules will be generated--flavor,-fl,--workflow,-wfl: the name of the workflow that will generate the necessary modules
--package-name,-pn: the name of the package, defaults togql--overwrite,-owt: if true, will overwrite everything
This addon comes with the following flavors:
relay_queries: generates relay style types(nodes), query, filter, orderrelay_mutations: generates relay style create/partial-update input types, mutationsquery_set_managers: A simple class with get_queryset, to help manage querysets in one place, normally not neededtests: coming soon
IMPORTANT!
Running a flavor with overwrite flag will replace the necessary modules made with other flavors to work with the currenty run flavor.
The addon has implemented a simple StrawberryJamTemplate class. The command looks for modules in the chunks/flavor_name/templates/ and initializes the Template subclass of StrawberryJamTemplate, which generates the necessary modules in the schema.
The relay_mutations flavor comes with extra. Instead of exposing to-many relations as a field, it exposes them via <field_name>_add and <field_name>_remove fields of type list[GlobalID], which let add remove fields by simply passing ids that need to be added or removed.
- Add generation of test modules
- Maybe add ability to run multiple flavors consecutively
- The generated schema will not work, if the types for relations are not generated. So maybe skip the fields for models that are not supplied to the command.