{"id":19376639,"url":"https://github.com/gavinray97/hasura-actions-codegen-plus","last_synced_at":"2025-04-23T18:33:25.373Z","repository":{"id":43976200,"uuid":"247575701","full_name":"GavinRay97/hasura-actions-codegen-plus","owner":"GavinRay97","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-12T05:31:51.000Z","size":8966,"stargazers_count":4,"open_issues_count":6,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-20T11:08:53.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GavinRay97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-16T00:23:37.000Z","updated_at":"2022-08-21T12:47:55.000Z","dependencies_parsed_at":"2023-01-27T14:15:25.608Z","dependency_job_id":null,"html_url":"https://github.com/GavinRay97/hasura-actions-codegen-plus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinRay97%2Fhasura-actions-codegen-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinRay97%2Fhasura-actions-codegen-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinRay97%2Fhasura-actions-codegen-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinRay97%2Fhasura-actions-codegen-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GavinRay97","download_url":"https://codeload.github.com/GavinRay97/hasura-actions-codegen-plus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250490595,"owners_count":21439171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T08:44:40.368Z","updated_at":"2025-04-23T18:33:23.640Z","avatar_url":"https://github.com/GavinRay97.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# codegen-builder-contrib\n\nA repo and tutorial to help build new codegens for Hasura (CLI and console).\n\n## Introduction\n\nCurrently, the Hasura CLI and console only do codegen for actions. This is roughly how actions codegen works:\n\n1. `hasura actions codegen \u003caction-name\u003e` or the codegen tab on the console will invoke the codegen\n\n\t  CLI                                     |  Console\n\t  :--------------------------------------:|:------------------------------------------:\n\t  ![cli-codegen](assets/codegen-cli.png)  |  ![console-codegen](assets/codegen-tab.png)\n\n2. This will invoke the codegen that was set in the `config.yaml` for the CLI, or the user selected dropdown in the console\n3. Every actions codegen script accepts arguments:\n  - `action-name`: The name of the action that you wish to codegen\n  - `actions-sdl`: All the actions and custom types definition in [GraphQL SDL](https://alligator.io/graphql/graphql-sdl/)\n  - `derive-payload`: When you derive an action from a Hasura mutation, this payload will be sent. In case of non-derived actions, this is `null`.\n\n    The actions codegen script should return an array of files where file is a JSON object of the following format:\n\n\t  ```json\n\t  {\n\t    \"name\": \"\u003cfilename\u003e.\u003cextension\u003e\",\n\t    \"content\": \"\u003cfile content\u003e\"\n\t  }\n\t  ```\n\n4. Example:\n\n\t  ```js\n\t  const templater = (actionName, actionsSdl, derive) =\u003e {\n\n\t    // your codegen logic\n\n\t    return [\n\t      {\n\t        name: \"file1.js\",\n\t\tcontent: 'console.log(\"This is an autogenerated file\")'\n\t      },\n\t      {\n\t      \tname: \"file2.js\",\n\t\tcontent: 'console.log(\"This is another autogenerated file\")'\n\t      }\n\t    ]\n\t  }\n\t  ```\n5. The hasura CLI or console then print the files in the directory or render the files and contents in the console UI respectively\n\n## Getting started\n\n1. Clone this repo\n    ```\n    git clone git@github.com:hasura/codegen-builder-contrib\n    cd codegen-builder-contrib\n    ```\n2. Run Hasura with the docker compose available locally:\n  ```\n  docker-compose up -d\n  ```\n3. Get the appropriate Hasura CLI binary for your operating system:\n    - [darwin](https://storage.googleapis.com/plugins-test/cli/cli-hasura-darwin-amd64)\n    - [linux](https://storage.googleapis.com/plugins-test/cli/cli-hasura-linux-amd64)\n    - [windows](https://storage.googleapis.com/plugins-test/cli/cli-hasura-windows-amd64.exe)\n\n## Load the initial schema and metadata to prepare for development\n\nThere are a few tables and actions already defined. Load them up:\n1. `cd hasura`\n2. `hasura migrate apply`\n3. `hasura metadata apply`\n\n## Run the sample codegen\n\nWe have setup a basic codegen (`actions-codegen.js`) in the `my-new-codegen` directory. To try it out:\n\n1. Run the codegen for the existing mutation `addNumbers`\n  ```\n  hasura actions codegen addNumbers\n  ```\n2. You should see a `my-new-codegen/codegen-output/file1.md` and a `my-new-codegen/codegen-output/file2.md`.\n\nThis codegen uses a Javascript script that is present in `my-new-codegen/actions-codegen.js`\n\n## Start playing with the `actions-codegen.js` script\n\nOpen up the `my-new-codegen/actions-codegen.js` file and start building your own codegen!\n\nFor reference, [check these codegen for `nodejs-zeit`](https://github.com/wawhal/actions-codegen/blob/master/nodejs-zeit/codegen.js).\n\nLimitations:\n- Because the codegen script is loaded dynamically, avoid loading external depedencies.\n- These are the libraries that are currently available that you can `require()` in your codegen script:\n  - graphql\n  - @graphql-codegen/core\n  - inflection\n- Codegen scripts support ES6 (use `require` for loading dependencies instead of `import`)\n\n## Publish your codegen for everyone so that it shows up in the CLI and the console\n\nLet's say you have to add a new codegen for a framework called `my-new-framework`.\n\n1. Clone [this repo](https://github.com/hasura/codegen-assets)\n2. Edit `frameworks.json` to include your `{ \"name\": \"my-new-codegen\" }`\n3. Create a new directory named `my-new-codegen` and add your codegen file to that directory as `actions-codegen.js`.\n\n### Starter Kit (optional)\n\nYou can also include a starterkit for `my-new-framework`. Add the starter kit as a directory called `starter-kit` to the `my-new-codegen/` directory and edit `frameworks.json` to change `{\"name\": \"my-new-framework\"}` to `{\"name\": \"my-new-framework\", \"hasStarterKit\": true }`. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinray97%2Fhasura-actions-codegen-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinray97%2Fhasura-actions-codegen-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinray97%2Fhasura-actions-codegen-plus/lists"}