简体   繁体   English

将 graphQL 与 API 网关(apollo-server-lambda)与 AppSync 一起使用

[英]Use graphQL with API Gateway (apollo-server-lambda) vs. AppSync

This is a question keeps confusing me.这是一个让我一直困惑的问题。 Although AppSync is marketed as for GraphQL while API Gateway is for REST.虽然 AppSync 以 GraphQL 的名义销售,而 API 网关则以 REST 的名义销售。 But API Gateway could also work with GraphQL via apollo server in lambda.但是 API 网关也可以通过 lambda 中的阿波罗服务器与 GraphQL 一起使用。

So what actually makes one a better option over the other?那么究竟是什么让一个比另一个更好的选择呢?

It depends on how much control you want over your backend service execution, how much code you feel like writing, and then of course how much you want to pay.这取决于您希望对后端服务执行的控制程度、您想编写多少代码,当然还有您想支付多少费用。

With API Gateway and Lambda you are writing a handler function that executes a full graphql request against your resolver definitions that you write in whatever language your Lambda runtime is set to. With API Gateway and Lambda you are writing a handler function that executes a full graphql request against your resolver definitions that you write in whatever language your Lambda runtime is set to. You have to consider how much memory your application will need, and what kind of features you want to support.您必须考虑您的应用程序需要多少 memory,以及您想要支持什么样的功能。 You will also need to do some legwork to get subscriptions working with websockets.您还需要做一些工作才能让订阅与 websockets 一起使用。

AWS AppSync is more of a managed service, where you register your GraphQL schema with AppSync and the service takes care of things like query validation, batching calls, and of course out-of-the-box subscriptions. AWS AppSync 更像是一项托管服务,您可以在其中向 AppSync 注册您的 GraphQL 架构,该服务负责查询验证、批处理调用,当然还有开箱即用的订阅。 In it you only need to define how you want to "map" the GraphQL request using VTL (Velocity Templating Language) to define calls to your downstream data sources ie.在其中,您只需要定义您希望如何使用 VTL(速度模板语言)“映射”GraphQL 请求来定义对下游数据源的调用,即。 specifically DynamoDB, ElasicSearch, HTTP, Aurora Serverless RDS, or Lambda.特别是 DynamoDB、ElasicSearch、HTTP、Aurora Serverless RDS 或 Lambda。 Keep in mind, the Lambda functions you write for AppSync only have to handle a single resolver, whereas with Apollo Server you are writing all of the resolver logic in your code.请记住,您为 AppSync 编写的 Lambda 函数只需处理单个解析器,而使用 Apollo Server,您将在代码中编写所有解析器逻辑。

Ultimately whichever way you choose has its pros and cons.最终,无论您选择哪种方式,都有其优点和缺点。 With Apollo Server on Lambda you get to control the full HTTP GraphQL request cycle at the expense of additional complexity to do so.使用 Lambda 上的 Apollo 服务器,您可以控制完整的 HTTP GraphQL 请求周期,但这样做会增加复杂性。 With AppSync you have a more "managed" service where you only need to define the resolvers to talk to your data sources (and in many cases, these can be auto-generated for you using Amplify CLI) at the expense of having finer control over the whole GraphQL request.使用 AppSync,您可以获得更“托管”的服务,您只需定义解析器即可与您的数据源对话(在许多情况下,这些可以使用 Amplify CLI 为您自动生成),但代价是更好地控制整个 GraphQL 请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是否必须在 lambda 中为 apollo graphql 使用 AppSync? - Do I have to use AppSync for apollo graphql in lambda? 将 AWS AppSync 用作 GraphQL 服务器 - Use AWS AppSync as a GraphQL Server 从 Lambda 调用 AWS AppSync graphql API - Calling AWS AppSync graphql API from Lambda 使用 Amazon api 网关用 REST API 包装 graphQL(appsync) - Wrapping graphQL(appsync) with REST API using Amazon api gateway 为什么您将使用AWS Lambda / API Gateway为无内容架构提供HTML内容而不是S3存储桶 - Why would you use AWS Lambda/API Gateway to serve up HTML content vs. S3 bucket for serverless architecture 无法使用 IAM 和 AppSyncClient 从 Lambda 验证到 AppSync GraphQL api - Unable to auth into AppSync GraphQL api from Lambda using IAM and AppSyncClient AWS Lambda function 无法访问 AppSync GraphQL API 权限被拒绝 - AWS Lambda function unable to access AppSync GraphQL API - permission denied 使用 Amazon api 网关使用 GET REST API 包装 graphQL(appsync) 时的映射请求 - Mapping request when Wrapping graphQL(appsync) with GET REST API using Amazon api gateway aws appsync graphql api 与 python - aws appsync graphql api with python 无法从 Lambda 调用 AppSync GraphQL api:TypeError:无法读取 Z37A6259CC0C1DAE299A78 的属性“匹配” - Unable to call AppSync GraphQL api from Lambda: TypeError: Cannot read property 'match' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM