为什么要使用 Apollo GraphQL Sever 进行 Express(或其他集成)? [英] Why Express (or other integration) with Apollo GraphQL Sever?

查看:27
本文介绍了为什么要使用 Apollo GraphQL Sever 进行 Express(或其他集成)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力理解 Express(或 Koa、Hapi 等)与 Apollo GraphQL 服务器集成的附加价值.

I am struggling to understand the added value of Express (or Koa, Hapi, etc) integration with Apollo GraphQL server.

我发现它可以在独立模式下很好地工作(例如:https://medium.com/codingthesmartway-com-blog/apollo-server-2-introduction-efc4026f5654).

I see it can work in stand alone mode very well (an example: https://medium.com/codingthesmartway-com-blog/apollo-server-2-introduction-efc4026f5654).

在哪种情况下我们应该使用(或不使用)集成?是什么推动了这个决定?

In which case should we use it with (or without) integration? What should drive this decision?

推荐答案

如果您只需要一个 GraphQL 端点,那么通常首选使用独立库 (apollo-server),因为编写更少的样板(订阅、文件上传等功能,无需额外配置即可工作).但是,除了公开单个 API 端点之外,许多应用程序还需要其他功能.示例包括:

If all you need is a GraphQL endpoint, then using the standalone library (apollo-server) is generally preferred because there will be less boilerplate to write (features like subscriptions, file uploads, etc. just work without additional configuration). However, many applications require additional functionality beyond just exposing a single API endpoint. Examples include:

  • 网络钩子
  • OAuth 回调
  • 会话管理
  • Cookie 解析
  • CSRF 保护
  • 监控或记录请求
  • 速率限制
  • 地理围栏
  • 提供静态内容
  • 服务端渲染

如果您的应用程序需要此类功能,那么您将需要利用像 Express 这样的 HTTP 框架,然后使用适当的集成库(即 apollo-server-express).

If you need this sort of functionality for your application, then you'll want to utilize an HTTP framework like Express and then use the appropriate integration library (i.e. apollo-server-express).

Apollo Server 还集成了无服务器解决方案 AWS Lambda.例如,如果您想采用无服务器技术以获得更好的可扩展性或消除系统管理成本,那么您还需要使用这些集成之一.

Apollo Server also includes integrations for serverless solutions AWS Lambda. If you want to go serverless to, for example, get better scalability or eliminate system admin costs, then you would also need to use one of these integrations.

这篇关于为什么要使用 Apollo GraphQL Sever 进行 Express(或其他集成)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆