简体   繁体   English

来自AWS无服务器反应应用程序的多个安全休息电话

[英]multiple secure rest call from aws serverless react app

I am developing app using react-reduce, appsync graphql and database as dynamoDB. 我正在使用react-reduce,appsync graphql和数据库作为dynamoDB开发应用程序。 so it's like below 所以就像下面

React <--> GraphQL <-> (AppSync) <--> resolver <--> DynamoDB

Now requirement wise there is a situation where i need to call multiple SSL certificate based REST API to get data, once data is fetched from REST API then get other data from DB ..merge those data and show it to UI. 现在需要明智的做法是,我需要调用多个基于SSL证书的REST API来获取数据,一旦从REST API中获取了数据,然后从DB中获取了其他数据。将这些数据合并并显示给UI。

for eg user data i need to display in UI, so database has 50% data for that user and rest of the data i need to fetch from multiple web service call. 例如,我需要在UI中显示用户数据,因此数据库具有该用户的50%数据,而我需要从多个Web服务调用中获取其余数据。

few options i have in mind or i have explored so far to address this situation. 我已经考虑过几种选择,或者到目前为止,我已经探索了解决这种情况的几种方法。 eg 例如

(Option:1) react <--> graphQL <--> AppSync <--> Pipeline Resolver (which will call one by one rest API call and then final resolver call will be DynamoDB) <--> REST API & DynamoDb

https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html

this option UI don't have to merge data, what ever is coming from pipeline resolver, UI can display. 此选项UI不必合并数据,无论管道解析器产生什么,UI都可以显示。

(Option:2) react -- single Lambda Function (for all necessary REST API call), Next GraphQL call -- AppSync -- DynamoDB

In option:2 UI has to get data from REST and DB and then merge and display. 在option:2中,UI必须从REST和DB获取数据,然后合并并显示。

(Option:3)

在此处输入图片说明

Option:3, i am not sure how feasible it is. 选项:3,我不确定它是否可行。 As of now i came up with above options. 截至目前,我想出了以上选择。 looking for right approach or best practices for such situation. 在这种情况下寻找正确的方法或最佳做法。

So ideally when building out a GraphQL gateway in AppSync, the idea should be that the UI developer doesn't have to think about the mechanics of where data comes from, rather they just work with the high-level entities particular to the application. 因此,理想情况下,在AppSync中构建GraphQL网关时,其想法应该是UI开发人员不必考虑数据来源的机制,而只需要与特定于应用程序的高级实体一起工作即可。 There are some scenarios where this isn't as optimal, but it's something to strive for. 在某些情况下,这并不是最佳选择,但需要努力。

If the result of a REST API call only maps to a single field, you can attach a nested resolver just to that field, even if there's a resolver at a higher level that's getting data from DynamoDB. 如果REST API调用的结果仅映射到单个字段,则可以将嵌套的解析程序仅附加到该字段,即使有一个更高级别的解析程序正在从DynamoDB获取数据。 However if that REST call returns values for multiple fields, or depends on data from the other REST calls, then a pipeline resolver makes sense here. 但是,如果该REST调用返回多个字段的值,或者依赖于其他REST调用中的数据,则此处使用管道解析器是有意义的。

You merge the data from multiple steps in a pipeline resolver is to take the output of each function call and add it to the $context.stash in the function response mapping template, which is a Map that is persisted throughout each function call in the pipeline resolver. 您需要合并管道解析器中多个步骤的数据,以获取每个函数调用的输出,并将其添加到函数响应映射模板的$context.stash中,该模板是一个Map,在管道中的每个函数调用中均会持久存在解析器。 Then in the Pipeline Resolver's response mapping template, you can read from the stash and assemple the data you want to return for that type in your schema. 然后,在Pipeline Resolver的响应映射模板中,您可以从存储中读取并在模式中分配要为该类型返回的数据。

Another benefit of GraphQL in this case that when the client UI doesn't need a particular field in an object, say that omitted field is found in a database that's slow to return, you don't have to actually call that database in the query resolver, as the client defines only the data it needs. GraphQL在这种情况下的另一个好处是,当客户端UI不需要对象中的特定字段时,例如说在返回缓慢的数据库中找到了被省略的字段,则无需在查询中实际调用该数据库。解析器,因为客户端仅定义它需要的数据。

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

相关问题 AWS无服务器和javascript - 它安全吗? - AWS serverless and javascript - is it secure? 使用代码使用无服务器React Web应用程序使用Cognito对AWS上的用户进行身份验证 - Authenticating users on AWS with Cognito for a serverless React web app using codes 使用 AWS 无服务器后端为 React 应用程序动态分配用户权限 - Dynamically assigning user permissions for a react app with an AWS serverless backend AWS ServerLess Web App示例 - AWS ServerLess Web App Example aws 无服务器多个 yaml java - aws serverless multiple yaml java AWS Serverless不接受多个变量 - AWS Serverless in not accepting multiple variables 来自Android应用程序的AWS API Gateway REST DELETE方法调用在模拟器中运行正常,但无法在设备上运行? - AWS API Gateway REST DELETE method call from android app working fine in emulator but not working from device? AWS Serverless 和 React 问题:有一个我需要构建的 react 应用程序,然后加载到 s3 存储桶以进行 static 托管 - AWS Serverless and React question: Have a react app that I need to build then load to an s3 bucket for static hosting 如何从 AWS Lambda 调用 REST API - How to call REST API from AWS Lambda 无服务器框架 - 在 AWS API Gateway 中将现有应用程序从 REST 切换到 HTTP - Serverless Framework - Switch existing application from REST to HTTP in AWS API Gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM