All Projects → dotansimha → envelop

dotansimha / envelop

Licence: MIT license
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.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to envelop

napari-hub
Discover, install, and share napari plugins
Stars: ✭ 44 (-93.02%)
Mutual labels:  plugins
RandomProxyRuby
Tiny Library for get random proxy (free).
Stars: ✭ 16 (-97.46%)
Mutual labels:  plugins
TuubesCore
Scalable server engine for voxel / cubic games
Stars: ✭ 48 (-92.38%)
Mutual labels:  plugins
eolinker-api-test-plugins
Eolinker API测试增强插件,需要搭配www.eolinker.com网站使用,支持Chrome以及Firefox浏览器,支持自动化测试、文件测试、跨域测试等。
Stars: ✭ 107 (-83.02%)
Mutual labels:  plugins
noplugin
Play legacy media in modern browsers without plugins.
Stars: ✭ 29 (-95.4%)
Mutual labels:  plugins
pMix2
pMix - a preset interpolator, plug-in chainer and Faust IDE written with JUCE
Stars: ✭ 84 (-86.67%)
Mutual labels:  plugins
gdbundle
Minimalist plugin manager for GDB and LLDB
Stars: ✭ 72 (-88.57%)
Mutual labels:  plugins
laravel-adminer
Adminer database management tool for your Laravel application.
Stars: ✭ 45 (-92.86%)
Mutual labels:  plugins
graphql-api
GraphQL-Api is an opinionated Graphql framework for Rails that supports auto generating queries based on Active Record models and plain Ruby objects
Stars: ✭ 58 (-90.79%)
Mutual labels:  graphql-schema
clifm
The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell
Stars: ✭ 825 (+30.95%)
Mutual labels:  plugins
bizhawk-shuffler-2
A script to randomly shuffle between games played in Bizhawk, with plugins to enhance the experience
Stars: ✭ 37 (-94.13%)
Mutual labels:  plugins
dsl-api-generator
Generates binary compatible and Java interoperable DSL boilerplate code
Stars: ✭ 25 (-96.03%)
Mutual labels:  plugins
graphql-cli-load
A graphql-cli data import plugin to call mutations with data from JSON/CSV files
Stars: ✭ 63 (-90%)
Mutual labels:  graphql-schema
plugins
Albert plugins
Stars: ✭ 83 (-86.83%)
Mutual labels:  plugins
helix-plugins
github.com/Bilwin/helix-plugins
Stars: ✭ 24 (-96.19%)
Mutual labels:  plugins
smuggler2
Minimise haskell imports, make exports explicit
Stars: ✭ 18 (-97.14%)
Mutual labels:  plugins
velero-plugin-example
Example project for plugins for Velero, a Kubernetes disaster recovery utility
Stars: ✭ 45 (-92.86%)
Mutual labels:  plugins
plugins
Collection of plugins for Windi CSS.
Stars: ✭ 64 (-89.84%)
Mutual labels:  plugins
kong-js-pdk
Kong PDK for Javascript and plugin server
Stars: ✭ 28 (-95.56%)
Mutual labels:  plugins
umeng analytics push
Umeng Analytics&Push Flutter Plugins
Stars: ✭ 28 (-95.56%)
Mutual labels:  plugins

Envelop

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 enrichs the feature set of your application.

@envelop/core: npm version

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
  • Low-level API for extending the execution layer
  • Agnostic to GraphQL Engine
  • Agnostic to the HTTP layer
  • Agnostic to the schema tools
  • Plugins-based usage
  • No vendor lock-in
  • Amazing TypeScript support

You can read more about the key concepts or Envelop here

Getting Started

Start by adding the core of Envelop to your codebase:

yarn add graphql @envelop/core

Then, create a simple Envelop based on your GraphQL schema:

import * as GraphQLJS from 'graphql'
import { envelop, useEngine, useSchema } from '@envelop/core'

const mySchema = buildSchema(/* ... */) // GraphQLSchema

const getEnveloped = envelop({
  plugins: [useEngine(GraphQLJS), useSchema(mySchema)]
})

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:

const httpServer = 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 it
  const { query, variables } = JSON.parse(req.payload)
  const document = parse(query)
  const validationErrors = validate(schema, document)

  if (validationErrors.length > 0) {
    return res.end(JSON.stringify({ errors: validationErrors }))
  }

  // Build the context and execute
  const context = await contextFactory(req)
  const result = await execute({
    document,
    schema,
    variableValues: variables,
    contextValue: context
  })

  // Send the response
  res.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 log all incoming requests, using the built-in plugins:

const getEnveloped = envelop({
  plugins: [useEngine(GraphQLJS), useSchema(schema), useLogger(), useTiming()]
})

You can read more about here

Integrations / Examples

You can find the integrations and compatibility list, and code-based examples here

Available 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.

Envelop's Plugin Hub

Sharing / Composing envelops

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.

You can read more about Sharing and Composing Envelops here.

Write your own plugin!

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

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

const myPlugin = {
  onExecute({ args }) {
    console.log('Execution started!', { args })

    return {
      onExecuteDone({ result }) {
        console.log('Execution done!', { result })
      }
    }
  }
}

const getEnveloped = envelop({
  plugins: [
    /// ... other plugins ...,
    myPlugin
  ]
})

For a complete guide and API docs for custom plugins, please refer to Envelop website

Contributing

If this is your first time contributing to this project, please do read our Contributor Workflow Guide before you get started off.

Feel free to open issues and pull requests. We're always welcome support from the community.

Code of Conduct

Help us keep Envelop open and inclusive. Please read and follow our of Conduct as adopted from Contributor Covenant

License

GitHub license

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].