{"id":13724977,"url":"https://github.com/ManUtopiK/fastify-hasura","last_synced_at":"2025-05-07T19:32:14.248Z","repository":{"id":43827069,"uuid":"343424293","full_name":"ManUtopiK/fastify-hasura","owner":"ManUtopiK","description":"A Fastify plugin to have fun with Hasura.","archived":false,"fork":false,"pushed_at":"2024-09-06T06:06:08.000Z","size":416,"stargazers_count":32,"open_issues_count":9,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-05T03:43:25.080Z","etag":null,"topics":["fastify","fastify-plugin","graphql","hasura"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ManUtopiK.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-01T13:22:38.000Z","updated_at":"2024-09-09T05:51:50.000Z","dependencies_parsed_at":"2024-01-05T10:40:20.508Z","dependency_job_id":"f0a024b4-66ca-4711-bdfe-dfddc59a1b85","html_url":"https://github.com/ManUtopiK/fastify-hasura","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.125,"last_synced_commit":"a11b3abdfad9ef66a4aa7e6c7f7dbdd999bb27a7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManUtopiK%2Ffastify-hasura","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManUtopiK%2Ffastify-hasura/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManUtopiK%2Ffastify-hasura/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManUtopiK%2Ffastify-hasura/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManUtopiK","download_url":"https://codeload.github.com/ManUtopiK/fastify-hasura/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645153,"owners_count":17346084,"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":["fastify","fastify-plugin","graphql","hasura"],"created_at":"2024-08-03T01:02:08.538Z","updated_at":"2024-11-14T15:30:33.554Z","avatar_url":"https://github.com/ManUtopiK.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Tools and Extensions"],"sub_categories":[],"readme":"![fastify-hasura.png](https://i.postimg.cc/6qhHHw8K/fastify-hasura.png)\n\n# fastify-hasura\n\n[![NPM version](https://img.shields.io/npm/v/fastify-hasura.svg?style=flat)](https://www.npmjs.com/package/fastify-hasura)\n[![Coverage Status](https://coveralls.io/repos/github/ManUtopiK/fastify-hasura/badge.svg?branch=master)](https://coveralls.io/github/ManUtopiK/fastify-hasura?branch=master)\n\nA [Fastify](https://github.com/fastify/fastify) plugin to have fun with [Hasura](https://github.com/hasura/graphql-engine).\n\n## Features\n\n- Fastify decorator over [graphql-request](https://github.com/prisma/graphql-request) to easily request Hasura graphql endpoint.\n- Provide routes for Hasura events, actions and cron jobs.\n- Secure requests coming from Hasura.\n- Easily register handler for Hasura events, actions and cron jobs.\n\n## Install\n\n1. Install fastify-hasura with:\n\n```sh\nyarn add fastify-hasura  # or npm i --save fastify-hasura\n```\n\n2. Register the plugin:\n\n```js\nfastify.register(require('fastify-hasura'), {\n  endpoint: 'yourHasuraGraphqlEndpoint',\n  admin_secret: 'yourAdminSecret'\n})\n```\n\n## Usage\n\n**Example request on Hasura Graphql Endpoint**\n\n```js\nconst userId = 'yourUserUUID'\n\nconst fetchUser = `#graphql\n  query fetchUser($id: uuid!) {\n    user: user_by_pk(id: $id) {\n      password\n    }\n  }\n`\nconst { user } = await fastify.hasura.graphql(fetchUser, {\n  id: userId\n})\n```\n\n**Example registering event and action:**\n\n```js\n// Register new_user hasura event\nfastify.hasura.registerEvent('new_user', (request, reply) =\u003e {\n  const user = request.event.getNewData()\n  console.log(user)\n})\n\n// Register login hasura action\nfastify.hasura.registerAction('login', async (request, reply) =\u003e {\n  const data = request.action.getData('id', 'type', 'user')\n  console.log(data)\n\n  const response = await yourAsyncCustomBusinessLogic(data)\n  reply.send(response)\n})\n```\n\n_**Note:** Requests for events and actions are decorated with [hasura-parser](https://github.com/snotra-org/hasura-parser). So, you can easily retrieve data in routes with `request.event` and `request.action`._\n\n### Options\n\n- `endpoint` **[ required ]**: Your Hasura Graphql Endpoint.\n- `admin_secret` **[ required ]**: Your Hasura admin secret.\n- `api_secret` **[ optional ]**: _Highly recommended._ Provide an api secret if you want to secure requests from your Hasura instance to your Fastify app. You must configure `x-hasura-from-env` headers of all Hasura events, actions and cron jobs with this api secret.\n- `routes_prefix` **[ optional ]**: By default, this plugin build root routes for `/events`, `/actions` and `/crons`. Use this option if you want to prefix this routes. Eg: `/hasura` will build routes `/hasura/events` and so on...\n\n**All options:**\n\n```js\nfastify.register(require('fastify-hasura'), {\n  endpoint: 'yourHasuraGraphqlEndpoint',\n  admin_secret: 'yourAdminSecret',\n  api_secret: 'yourApiSecret',\n  routes_prefix: '/hasura'\n})\n```\n\n## More documentation\n\n- [Hasura GraphQL Engine Documentation](https://hasura.io/docs/latest/graphql/core/index.html)\n- [graphql-request](https://www.npmjs.com/package/graphql-request)\n- [hasura-parser](https://github.com/snotra-org/hasura-parser)\n\n## Contributions\n\nIf you would like to make any contribution you are welcome to do so.\n\n## License\n\nLicensed under [MIT](https://github.com/ManUtopiK/fastify-hasura/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FManUtopiK%2Ffastify-hasura","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FManUtopiK%2Ffastify-hasura","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FManUtopiK%2Ffastify-hasura/lists"}