Actions need HTTP handlers to run the business logic. It might be inconvenient to write the complete handler code for every action. Luckily, GraphQL's type system allows us to auto-generate the boilerplate code for actions.
Hasura currently has codegen set up for a few frameworks. The list of supported frameworks should grow with contributions from the community.
Generating handler code for your action
Head to the
Actions -> [action-name] -> Codegen tab in the console
You can select the framework of your choice to get the corresponding handler boilerplate code.
Before being able to codegen for actions, you have to configure your CLI.
hasura actions use-codegen
Choose which framework you want to codegen for:
Choose if you also wish to clone a starter kit for the chosen framework:
Choose a path where you want to output the auto-generated code files
This command will update your
config.yaml with the codegen config as per your preferences. You can also set these
values manually in
To finally get auto-generated code for an action, run:
hasura actions codegen <action-name>
The codegen files will be generated at the
output_dir path from
Codegen for your framework
As of now, Hasura provides codegen for a few frameworks (
python-flask and many
more). You can see the full list in the
Codegen tab on the console after you've
created an action.
We will continue adding more examples to the documentation.
Building your own codegen
If you wish to build a code generator for your framework read the contrib guide.
Introduction to Hasura Actions - View Recording.