在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):n1ru4l/envelop开源软件地址(OpenSource Url):https://github.com/n1ru4l/envelop开源编程语言(OpenSource Language):TypeScript 87.1%开源软件介绍(OpenSource Introduction):Envelop
Envelop Key Concepts
You can read more about the key concepts or Envelop here Getting StartedStart by adding the core of Envelop to your codebase:
Then, create a simple Envelop based on your GraphQL schema: import { envelop, useSchema } from '@envelop/core';
const mySchema = buildSchema( ... ); // GraphQLSchema
const getEnveloped = envelop({
plugins: [
useSchema(mySchema)
],
}); The result of const httpServer = createServer();
httpServer.on('request', (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: [useSchema(schema), useLogger(), useTiming()],
}); Integrations / ExamplesYou can find the integrations and compatibility list, and code-based examples here Available PluginsYou 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
Sharing / Composing |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论