You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
envelop is a lightweight JavaScript (/TypeScript) library for wrapping GraphQL execution layer and
flow, allowing developers to develop, share and collaborate on GraphQL-related plugins while filling
the missing pieces in GraphQL implementations.
envelop aims to extend the GraphQL execution flow by adding plugins that enrich the feature set of
your application.
@envelop/core:
Envelop is created and maintained by The Guild, and used in production
by our clients.
Envelop Key Concepts
Lightweight
Wraps the entire GraphQL pipeline, based on plugins
The result of envelop is a function that allows you to get everything you need for the GraphQL
execution: parse, validate, contextBuilder and execute. Use that to run the client's GraphQL
queries. Here's a pseudo-code example of how it should look like:
consthttpServer=createServer()httpServer.on('request',async(req,res)=>{// Here you get the alternative methods that are bundled with your plugins// You can also pass the "req" to make it available for your plugins or GraphQL context.const{ parse, validate, contextFactory, execute, schema }=getEnveloped({ req })// Parse the initial request and validate itconst{ query, variables }=JSON.parse(req.payload)constdocument=parse(query)constvalidationErrors=validate(schema,document)if(validationErrors.length>0){returnres.end(JSON.stringify({errors: validationErrors}))}// Build the context and executeconstcontext=awaitcontextFactory(req)constresult=awaitexecute({
document,
schema,variableValues: variables,contextValue: context})// Send the responseres.end(JSON.stringify(result))})httpServer.listen(3000)
Behind the scenes, this simple workflow allows you to use Envelop plugins and hook into the
entire request handling flow.
Here's a simple example for collecting metrics and logging all incoming requests, using the built-in
plugins:
You can explore all plugins in our Plugins Hub. If you wish your
plugin to be listed here and under PluginsHub, feel free to add your plugin information
in this file and
create a Pull Request!
We provide a few built-in plugins within the @envelop/core, and many more plugins as standalone
packages.
After an envelop has been created, you can share it with others as a complete layer of plugins.
This is useful if you wish to create a predefined layer of plugins, and share it with others. You
can use it as a shell and as a base for writing shareable pieces of servers.
Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.