|
1 | 1 | ## Envelop |
2 | 2 |
|
3 | | -Envelop is a lightweight JavaScript 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. |
| 3 | +`envelop` is a lightweight JavaScript (/TypeScript) library for wrapping GraphQL execution layer and flow, allowing developers to develop, share |
| 4 | +and collaborate on GraphQL-related plugins while filling the missing pieces in GraphQL implementations. |
4 | 5 |
|
5 | | -<p align="left"> |
| 6 | +`envelop` aims to extend the GraphQL execution flow by adding plugins that enrichs the feature set of your application. |
| 7 | + |
| 8 | +<p align="center"> |
6 | 9 | <img height="150" src="./logo.png"> |
7 | 10 | </p> |
8 | 11 |
|
9 | | -`@envelop/core`: [](https://badge.fury.io/js/%40envelop%2Fcore) |
| 12 | +`@envelop/core`: [](https://www.npmjs.com/package/@envelop/core) |
10 | 13 |
|
11 | 14 | > Envelop is created and maintained by [The Guild](https://the-guild.dev/), and used in production by our clients. |
12 | 15 |
|
13 | | -### In depth |
14 | | - |
15 | | -Our goal is to allow developers to keep the original GraphQL interfaces, while adding plugins to enrich the feature set of your application quickly, while sharing ideas, code and plugins with other developers. |
| 16 | +### [Envelop Key Concepts]((https://www.envelop.dev/docs#key-concepts)) |
16 | 17 |
|
17 | | -Envelop is agnostic to the HTTP server you use, so it's not a traditional server. We do not aim to provide a complete server, you can use Envelop with any environment (NodeJS or browser) and any type of GraphQL workflow (client / server, client-side execute, or server to server). So any piece of code that uses GraphQL's `execute` can benefit from that layer. |
| 18 | +* Lightweight |
| 19 | +* Wraps the entire GraphQL pipeline, based on plugins |
| 20 | +* Low-level API for extending the execution layer |
| 21 | +* Agnostic to the HTTP layer |
| 22 | +* Agnostic to the schema tools |
| 23 | +* Plugins-based usage |
| 24 | +* No vendor-locking |
18 | 25 |
|
19 | | -The core of Envelop is zero-dependency, and will only apply changes to your GraphQL execution based on the plugins you wish to use. It can be integrated with any GraphQL server that follows [the execution phase, as defined in the GraphQL spec](https://spec.graphql.org/June2018/#sec-Executing-Requests) and let you provide your own lifecycle methods. |
| 26 | +[You can read more about the key concepts or Envelop here](https://www.envelop.dev/docs#key-concepts) |
20 | 27 |
|
21 | | -Separating the execution workflow and the logic that it runs in each phase allow you to write reusable piece of code, like logging, metric collection, error handling, custom validations, resolvers tracing (and integration with any external), authentication, authorization and much more, without the needs to write it explicitly every time, or in any project or microservice. With Envelop, you can easily create a wrapper around your common logics, and share it with others. |
22 | | - |
23 | | -## Getting Started |
| 28 | +## [Getting Started](https://www.envelop.dev/docs/getting-started) |
24 | 29 |
|
25 | 30 | Start by adding the core of Envelop to your codebase: |
26 | 31 |
|
@@ -86,27 +91,16 @@ const getEnveloped = envelop({ |
86 | 91 | }); |
87 | 92 | ``` |
88 | 93 |
|
89 | | -> Envelop `plugins` are based on a simple event-based contact, that allow you easily to add more logic to your app. You can easily share and collaborate on plugins that you find generic. |
90 | | -
|
91 | | -## Integrations / Examples |
| 94 | +> [You can read more about here](https://www.envelop.dev/docs/getting-started) |
92 | 95 |
|
93 | | -Envelop provides a low-level API at consumption of the output, but a rich API while using it with plugins. Based on that, it's possible to integrate Envelop with many tools. |
| 96 | +## [Integrations / Examples](https://www.envelop.dev/docs/integrations) |
94 | 97 |
|
95 | | -We recommend using [`graphql-helix`](https://github.com/contrawork/graphql-helix) as the request pipeline orchestrator, as it allows the maximum flexibility and you can easily override/manage every part of the pipeline with Envelop. |
96 | | - |
97 | | -Here's a list of integrations and examples: |
98 | | - |
99 | | -| Server/Framework | Fully supported? | Example | |
100 | | -| ---------------- | ---------------- | ------------------------------------------- | |
101 | | -| Node's `http` | V | [`basic-http`](./examples/simple-http) | |
102 | | -| GraphQL-Helix | V | [`graphql-helix`](./examples/graphql-helix) | |
103 | | -| Apollo-Server | Almost | [`apollo-server`](./examples/apollo-server) | |
104 | | -| GraphQL-WS | V | [`graphql-ws`](./examples/graphql-ws) | |
105 | | - |
106 | | -> Since Envelop is not a HTTP server, and just a wrapper around GraphQL request pipeline - it's possible to integrate it with any server/framework, if it's flexible enough and allows you to specify the pipeline methods\*. |
| 98 | +[You can find the integrations and compatibility list, and code-based examples here](https://www.envelop.dev/docs/integrations) |
107 | 99 |
|
108 | 100 | ## Available Plugins |
109 | 101 |
|
| 102 | +You can explore all plugins in our [Plugins Hub](https://www.envelop.dev/plugins). If you wish your plugin to be listed here and under PluginsHub, feel free to add your plugin information [in this file](https://github.com/dotansimha/envelop/edit/main/website/src/lib/plugins.ts#L23) and create a Pull Request! |
| 103 | + |
110 | 104 | We provide a few built-in plugins within the `@envelop/core`, and many more plugins as standalone packages. |
111 | 105 |
|
112 | 106 | | Name | Package | Description | |
@@ -141,23 +135,7 @@ We provide a few built-in plugins within the `@envelop/core`, and many more plug |
141 | 135 |
|
142 | 136 | 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 sharable pieces of servers. |
143 | 137 |
|
144 | | -Here's a small exmple for sharing envelops: |
145 | | - |
146 | | -```ts |
147 | | -// Somewhere where you wish to create the basics of what you wish to share |
148 | | -// This defined the base plugins you wish to use as base. |
149 | | -const myBaseEnvelop = envelop({ |
150 | | - plugins: [useOrgAuth(), useOrgTracing(), useOrgLogsCollector()], |
151 | | -}); |
152 | | - |
153 | | -// Later, when you create your own Envelop, you can extend that and add custom plugins. |
154 | | -// You can also specify the schema only at this point |
155 | | -const myEnvelop = envelop({ |
156 | | - plugins: [useEnvelop(myBaseEnvelop), useSchema(myServerSchema), useMyCustomPlugin()], |
157 | | -}); |
158 | | -``` |
159 | | - |
160 | | -This approach allows developers to create a base Envelop and share it across the organization: you can define your monitoring setup, logging, authentication, etc, only once in a common package, and share it with others without losing the ability to extend it. |
| 138 | +You can read more about [Sharing and Composing Envelops here](https://www.envelop.dev/docs/composing-envelop). |
161 | 139 |
|
162 | 140 | ## Write your own plugin! |
163 | 141 |
|
@@ -186,56 +164,7 @@ const getEnveloped = envelop({ |
186 | 164 | }); |
187 | 165 | ``` |
188 | 166 |
|
189 | | -> Feel free to share you plugin with us, or with the community. Sharing = Caring! |
190 | | -
|
191 | | -#### The plugin interface |
192 | | - |
193 | | -You can find it here: https://github.com/dotansimha/envelop/blob/main/packages/types/src/index.ts#L50 |
194 | | - |
195 | | -#### Execution Lifecycle |
196 | | - |
197 | | -By extending the GraphQL execution pipeline, we allow developers to write reusable plugins, that can be shared with others easily, as NPM packages. So instead of delivering a bloated GraphQL server with tons of features, we allow you to choose the HTTP server you prefer, the request pipeline you prefer, and the features you prefer. |
198 | | - |
199 | | -We wrap the execution pipeline of GraphQL operation, and allow Envelop plugins to do the following: |
200 | | - |
201 | | -- `parse` |
202 | | - - Hook into the before/after of this phase |
203 | | - - Override the parse function |
204 | | - - Access to the parsed result |
205 | | - - Modify the parsed result |
206 | | -- `validate` |
207 | | - - Hook into the before/after of this phase |
208 | | - - Override the validation function |
209 | | - - Access to the validation error results |
210 | | - - Modify the validation results |
211 | | - - Add custom validation rules |
212 | | -- `contextFactory` |
213 | | - - Hook into the before/after of this phase |
214 | | - - Access to the initial HTTP request context |
215 | | - - Extend the context with custom data |
216 | | - - Replace the context object |
217 | | -- `execute` |
218 | | - - Hook into the before/after of this phase |
219 | | - - Extend the execution context |
220 | | - - Access to all execution parameters |
221 | | - - Replace the execute function |
222 | | - - Access to the results / error of the execution |
223 | | - - Access to before / after resolvers calls |
224 | | - - Extend resolvers behavior |
225 | | - - Access resolvers parameters |
226 | | - - Replace / modify the execution result |
227 | | -- `subscribe` |
228 | | - - Hook into the before/after of this phase |
229 | | - - Extend the execution context |
230 | | - - Access to all execution parameters |
231 | | - - Replace the execute function |
232 | | - - Access to the results / error of the execution |
233 | | - - Access to before / after resolvers calls |
234 | | - - Extend resolvers behavior |
235 | | - - Access resolvers parameters |
236 | | - - Replace / modify the subscription result |
237 | | - |
238 | | -We also allow you to change the GraphQL schema during execution - so if your server has a schema that could change dynamically, you can always update it. As a result, we trigger `schemaChange` event that allow plugins respond accordingly. |
| 167 | +[For a complete guide and API docs for custom plugins, please refer to Envelop website](https://www.envelop.dev/docs/plugins) |
239 | 168 |
|
240 | 169 | ### Contributing |
241 | 170 |
|
|
0 commit comments