The Guild LogoThe Guild Monogram

Search docs

Search icon

Products by The Guild

Products

Hive logoHive blurred logo

Hive

Schema Registry for your GraphQL Workflows

Envelop Logo

Envelop

Get Started

Custom Plugins#

envelop plugins are just objects with functions that provide a contextual implementation for before/after each phase, with a flexible API.

If you are using TypeScript and with to leverage the type-system, you can import the Plugin interface from @envelop/types package, and implement it.

Simple Plugin#

Here's a simple example that allows you to print the execution and parsing params:

import { Plugin } from '@envelop/types'; const myPlugin: Plugin = { onParse({ params }) { console.log('Parse started!', { args }); return result => { console.log('Parse done!', { result }); }; }, onExecute({ args }) { console.log('Execution started!', { args }); return { onExecuteDone: ({ result }) => { console.log('Execution done!', { result }); }, }; }, }; const getEnveloped = envelop({ plugins: [ /// ... other plugins ..., myPlugin, ], });

Configurable Plugin#

If your plugin requires additional configuration you with to pass to it, you can create your plugins as a function, and accept the configuration there:

const myPlugin = (printResult): Plugin => { return { onExecute({ args }) { console.log('Execution started!', { args }); return { onExecuteDone: ({ result }) => { if (printResult) { console.log('Execution done!', { result }); } }, }; }, }; }; const getEnveloped = envelop({ plugins: [ /// ... other plugins ..., myPlugin(true), ], });