|
1 | 1 | # Stackables Webhooks |
2 | 2 |
|
3 | | -GraphQL Code Generator plugin for Stackables webhooks |
| 3 | +GraphQL Code Generator plugin for Stackables webhooks. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +This is a plugin for GraphQL Code Generator. [See official installation docs for more info](https://www.graphql-code-generator.com/docs/getting-started/installation). |
| 8 | + |
| 9 | +All packages should be installed as dev dependencies and are used only during development. |
4 | 10 |
|
5 | 11 | ```bash |
6 | | -npm add codegen-stackables-webhooks@beta |
| 12 | +# install generator cli |
| 13 | +npm install --save-dev @graphql-codegen/cli |
| 14 | + |
| 15 | +# required typescript plugins |
| 16 | +npm install --save-dev @graphql-codegen/typescript |
| 17 | +npm install --save-dev @graphql-codegen/typescript-operations |
| 18 | + |
| 19 | +# webhooks plugin |
| 20 | +npm install --save-dev codegen-stackables-webhooks@beta |
| 21 | +``` |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +While GraphQL Code Generator configuration is simple we still recommend to use the [graphql configuration](https://graphql-config.com/introduction) for more universal configuration. |
| 26 | + |
| 27 | +We also provide a simple utility to help with the verbosity. But you can always take full control when you need to. |
| 28 | + |
| 29 | +`graphql.config.js` in repository root |
| 30 | + |
| 31 | +```js |
| 32 | +const { getConfiguration } = require('stackables-webhooks'); |
| 33 | + |
| 34 | +// Returned configuration is just a plain object |
| 35 | +// So if needed you can add or modify the returned setting as needed |
| 36 | + |
| 37 | +module.exports = getConfiguration({ |
| 38 | + generatedFile: "<string>", |
| 39 | + accountSlug: "<string>", |
| 40 | + introspectionToken: "<string>" |
| 41 | +}) |
| 42 | +``` |
| 43 | + |
| 44 | +[See full configuration options here](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/config.md) |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +Generated types are easy to use with [cloudevents-router](https://github.com/stackables/cloudevents-router) package. |
| 49 | + |
| 50 | +```typescript |
| 51 | +import { CloudEventsRouter } from 'cloudevents-router' |
| 52 | +import { FragmentRegistry } from './src/generated/webhooks' |
| 53 | + |
| 54 | +const router = new CloudEventsRouter<FragmentRegistry>() |
| 55 | + |
| 56 | +router.on('stackables.webhook.v1.YourHookName', async (event) => { |
| 57 | + console.log('Received typed webhook', event.data) |
| 58 | +}) |
7 | 59 | ``` |
8 | 60 |
|
9 | | ---- |
| 61 | +See more options on how to use the router with different web servers [here](https://github.com/stackables/cloudevents-router). But simplest is to just use nodejs built in web server like this: |
| 62 | + |
| 63 | +```typescript |
| 64 | +import http from "http" |
| 65 | +import { getMiddleware } from "cloudevents-router" |
| 66 | + |
| 67 | +// const router = ... |
| 68 | + |
| 69 | +const middleware = getMiddleware(router, { path: '/' }) |
| 70 | +const server = http.createServer(middleware) |
| 71 | + |
| 72 | +server.listen(5000); |
| 73 | +``` |
| 74 | + |
| 75 | +## Advanced Usage |
| 76 | + |
| 77 | +- [Payload structure](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/advanced.md) |
| 78 | +- [Provided configuration](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/advanced.md) |
| 79 | +- [Callback tokens](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/advanced.md) |
| 80 | +- [Branches](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/advanced.md) |
| 81 | + |
| 82 | +## Deployment options |
| 83 | + |
| 84 | +You can deploy the created web service anywhere as long as its publicly accessible. **But,** You need to ensure that you validate the Stackables JWT token. [Instructions here](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/deploy.md) |
| 85 | + |
| 86 | +You can also use Stackables cloud to host your webhooks, in this case authentication and scaling is taken care of by us. [Instructions here](https://github.com/stackables/codegen-stackables-webhooks/blob/beta/docs/deploy.md) |
10 | 87 |
|
11 | | -_Stackables service is still in closed beta, but we plan to open up for more users before the end of the year_ |
| 88 | +## Thats it ... |
12 | 89 |
|
13 | | -_For more info you can reach us at info@stackables.io_ |
| 90 | +... happy coding :) |
0 commit comments