express-graphql 中的 serverless 还是 serverfull?

问题描述

我正在向自己介绍无服务器并偶然发现:https://github.com/serverless-components/express 并且似乎无法理解部署到 heroku 的 serverfull 有什么区别?看看我在无服务器中有这个代码:

app.use(
  "/graphql",graphqlHTTP(async (request) => {
    // add user context
    console.log("test");
    return {
      schema,graphiql: true,context: {
        request,//user
      },};
  })
);

module.exports = app;

和服务器:

app.use(
  "/graphql",graphqlHTTP(async (request) => {
    // add user context
    return {
      schema,},};
  })
);

app.listen(port,() => console.log(`Listening on port ${port}`));

有人可以告诉我在 express-graphql 中使用无服务器是否有优势?我的前端堆栈是 graphql-relay,我习惯于 express-graphql 并想使用 express-graphql 堆栈探索无服务器,但似乎无法找到一个好的资源来做到这一点。当我从 this 阅读时:

在这一点上,我认为值得注意的是,并非所有人都同意 在无服务器功能中运行 Express 是一个好主意。作为保罗 约翰斯顿解释说,如果您正在构建规模化的功能,那就是 最好将每个功能分解成自己的 单一用途的功能。像我一样使用 Express 意味着每个 当请求到达 API 时,整个 Express 服务器必须 从头开始 - 效率不高。部署到生产环境 您自己承担风险。

请解释一下

解决方法

无服务器的一些好处:与将 24/7 全天候运行的传统服务器相比,您仅在需要时才按需执行代码。 此外,它还由服务提供商管理,因此您无需担心维护和扩展服务器。

你可以阅读更多

https://dashbird.io/blog/business-benefits-of-serverless/#:~:text=A%20company%20that%20can%20draw,will%20improve%20the%20user%20experience

https://www.serverless.com/blog/running-scalable-reliable-graphql-endpoint-with-serverless

https://aws.amazon.com/serverless/

https://serverless.com/blog/serverless-architecture-code-patterns/

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...