All Projects → ManUtopiK → fastify-hasura

ManUtopiK / fastify-hasura

Licence: MIT license
A Fastify plugin to have fun with Hasura.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fastify-hasura

create-fastify-app
An utility that help you to generate or add plugin to your Fastify project
Stars: ✭ 53 (+76.67%)
Mutual labels:  fastify, fastify-plugin
fastify-awilix
Dependency injection support for fastify
Stars: ✭ 52 (+73.33%)
Mutual labels:  fastify, fastify-plugin
fastify-etag
Automatically generate etags for HTTP responses, for Fastify
Stars: ✭ 61 (+103.33%)
Mutual labels:  fastify, fastify-plugin
fastify-postgres
Fastify PostgreSQL connection plugin
Stars: ✭ 144 (+380%)
Mutual labels:  fastify, fastify-plugin
fastify-cron
Run cron jobs alongside your Fastify server 👷
Stars: ✭ 32 (+6.67%)
Mutual labels:  fastify, fastify-plugin
session
Session plugin for fastify
Stars: ✭ 52 (+73.33%)
Mutual labels:  fastify, fastify-plugin
fastify-cors
Fastify CORS
Stars: ✭ 212 (+606.67%)
Mutual labels:  fastify, fastify-plugin
fastify-caching
A Fastify plugin to facilitate working with cache headers
Stars: ✭ 123 (+310%)
Mutual labels:  fastify, fastify-plugin
fastify-accepts
Add accepts parser to fastify
Stars: ✭ 51 (+70%)
Mutual labels:  fastify, fastify-plugin
fastify-loader
The route loader for the cool kids!
Stars: ✭ 17 (-43.33%)
Mutual labels:  fastify, fastify-plugin
fastify-webpack-hmr
Webpack hot module reloading for Fastify
Stars: ✭ 29 (-3.33%)
Mutual labels:  fastify, fastify-plugin
fastify-vue
A nuxt.js fastify plugin
Stars: ✭ 27 (-10%)
Mutual labels:  fastify, fastify-plugin
fastify-leveldb
Plugin to share a common LevelDB connection across Fastify.
Stars: ✭ 19 (-36.67%)
Mutual labels:  fastify, fastify-plugin
fastify-file-upload
Fastify plugin for uploading files
Stars: ✭ 68 (+126.67%)
Mutual labels:  fastify, fastify-plugin
fastify-csrf
A fastify csrf plugin.
Stars: ✭ 88 (+193.33%)
Mutual labels:  fastify, fastify-plugin
fastify-passport
Use passport strategies for authentication within a fastify application
Stars: ✭ 150 (+400%)
Mutual labels:  fastify, fastify-plugin
fastify-axios
Add axios http client to your fastify instance
Stars: ✭ 28 (-6.67%)
Mutual labels:  fastify, fastify-plugin
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+1556.67%)
Mutual labels:  fastify, fastify-plugin
fastify-openapi-glue
A plugin for Fastify to autogenerate a configuration based on a OpenApi(v2/v3) specification.
Stars: ✭ 94 (+213.33%)
Mutual labels:  fastify, fastify-plugin
fastify-env
Fastify plugin to check environment variables
Stars: ✭ 129 (+330%)
Mutual labels:  fastify, fastify-plugin

fastify-hasura.png

fastify-hasura

NPM version Coverage Status

A Fastify plugin to have fun with Hasura.

Features

  • Fastify decorator over graphql-request to easily request Hasura graphql endpoint.
  • Provide routes for Hasura events, actions and cron jobs.
  • Secure requests coming from Hasura.
  • Easily register handler for Hasura events, actions and cron jobs.

Install

  1. Install fastify-hasura with:
yarn add fastify-hasura  # or npm i --save fastify-hasura
  1. Register the plugin:
fastify.register(require('fastify-hasura'), {
  endpoint: 'yourHasuraGraphqlEndpoint',
  admin_secret: 'yourAdminSecret'
})

Usage

Example request on Hasura Graphql Endpoint

const userId = 'yourUserUUID'

const fetchUser = `#graphql
  query fetchUser($id: uuid!) {
    user: user_by_pk(id: $id) {
      password
    }
  }
`
const { user } = await fastify.hasura.graphql(fetchUser, {
  id: userId
})

Example registering event and action:

// Register new_user hasura event
fastify.hasura.registerEvent('new_user', (request, reply) => {
  const user = request.event.getNewData()
  console.log(user)
})

// Register login hasura action
fastify.hasura.registerAction('login', async (request, reply) => {
  const data = request.action.getData('id', 'type', 'user')
  console.log(data)

  const response = await yourAsyncCustomBusinessLogic(data)
  reply.send(response)
})

Note: Requests for events and actions are decorated with hasura-parser. So, you can easily retrieve data in routes with request.event and request.action.

Options

  • endpoint [ required ]: Your Hasura Graphql Endpoint.
  • admin_secret [ required ]: Your Hasura admin secret.
  • 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.
  • 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...

All options:

fastify.register(require('fastify-hasura'), {
  endpoint: 'yourHasuraGraphqlEndpoint',
  admin_secret: 'yourAdminSecret',
  api_secret: 'yourApiSecret',
  routes_prefix: '/hasura'
})

More documentation

Contributions

If you would like to make any contribution you are welcome to do so.

License

Licensed under MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].