Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-web-hook

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-web-hook

GWH provides a flexible and simple tool to executes and manages webhooks in a GraphQL environement.

  • 1.3.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Graphql-Web-Hook

GWH provides a flexible and simple tool to executes and manages webhooks in a GraphQL environement.

It is based on graphql-sequelize-generator and inspired by graphql-node-jobs.

How to use

classic use case

const { getCallWebhook } = require('graphql-web-hook')

...

function getMetadataFromContext(context) {
  return { userId: context.user.id }
}
...

const callWebhook = getCallWebhook(getMetadataFromContext)

await callWebhook({
  evenType: 'publish',
  context: {
    userId: 1,
    ...
  },
  data: {
    text: 'New post publish',
  },
})

How setup

Add GWH to your repository

yarn add graphql-web-hook

Migrate models

yarn run gnj migrate <configPath>

Add server apollo to your express server

const { getApolloServer } = require('graphql-web-hook')

const webhookServer = await getApolloServer({
  dbConfig,
  apolloServerOptions: { context: ({ req }) => req },
  getMetadataFromContext: (context) => {
    return getUserIdFromContext(context)
  },
)}

webhookServer.applyMiddleware({
  app,
  path: '/webhook/graphql',
})


app.use('/webhook', [middleware])

Documentation

getCallWebhook

This function initializes and returns callWebhook by assigning it getMetadataFormContext function.

Params :

  • getMetadataFromContext : function that should return the securityMetadata of a webhooks from a context.

callWebhook

Function to call webhook.

How it works :

  • Retrieves webhooks according to the type of event and its security metadata
  • Make request to all webhook with the associated data

Params :

  • data : data to be sent to the webhook
  • eventType : type of event
  • context : context related to the event

getMetadataFromContext

The purpose of this function is to return the security parameters of a webhook from a context. (It's called when you fetch a webhook)

Example :

const { getApolloServer } = require('graphql-web-hook')

...

getApolloServer({
  ...
  getMetadataFromContext: (context) => {
    return getUserIdFromContext(context)
  }
}

Contributing

Install environnement

yarn :

  apt-get install git curl yarn
  # or
  brew install git curl yarn
Project
git clone git@github.com:teamstarter/graphql-web-hooks.git
cd graphql-web-hooks
yarn
yarn start
Test the migration script locally
yarn run gnj migrate ./../tests/sqliteTestConfig.js
Start a test server using the test database migrated previously
yarn start
Running the test
yarn test

Debugging a specific test

node --inspect-brk ./node_modules/jest/bin/jest.js ./tests/job.spec.js

FAQs

Package last updated on 29 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc