简体   繁体   English

在AWS lambda上运行graphql应用程序

[英]Running a graphql app on AWS lambda

I'm trying to run an apollo graphql server on AWS lambda. 我正在尝试在AWS lambda上运行apollo graphql服务器。 The current architecture of the server is this - 服务器的当前架构是这样的 -

One main lambda function which holds the schema and this is the function that the client talks to. 一个主要的lambda函数,它保存模式,这是客户端与之交谈的功能。 Each resolver in this function calls other lambda functions that holds the core logic of the resolver. 此函数中的每个解析器都会调用其他lambda函数来保存解析器的核心逻辑。 Other lambda functions are called using lambda.invoke method. 使用lambda.invoke方法调用其他lambda函数。

A bunch of other lambda functions each holding logic for a specific tasks. 一堆其他lambda函数,每个函数都包含特定任务的逻辑。 These will be used by resolvers in main lambda function. 这些将由主lambda函数中的解析器使用。 These functions also talk to dynamoDB for storage. 这些函数还与dynamoDB通信以进行存储。

Problem - Client makes a request, the main lambda function receives it, calls another lambda function for results, the main function gets the result, returns the result to the user. 问题 - 客户端发出请求,主lambda函数接收它,调用另一个lambda函数获取结果,main函数获取结果,将结果返回给用户。 The main lambda function is running unnecessarily till it gets result back from the lambda function that it invoked. 主lambda函数不必要地运行,直到它从它调用的lambda函数返回结果为止。 This is increase cost and there could also be chains going more that 2 levels. 这是增加成本,也可能有超过2个级别的链。

One solution that was suggested was to jam up everything into one function. 建议的一个解决方案是将所有内容都集中到一个功能中。 But wouldn't that be difficult to scale in future? 但是将来难以扩展吗? And when it grows I'll again start facing the same problem. 当它增长时,我将再次开始面临同样的问题。

How to typically people structure their graphql server on lambda? 如何通常人们在lambda上构建他们的graphql服务器?

I've run the "jam everything into one lambda function" architecture in production for about a year now, it scales quite well (hundreds of users requesting bulky GIS data, team of 5 or so developers building the resolvers). 我已经在生产中运行了“将所有内容整合到一个lambda函数”架构中大约一年,它可以很好地扩展(数百个用户请求庞大的GIS数据,团队由5个左右的开发人员构建解析器)。

I've written a reference implementation on GitHub if you'd like to see: https://github.com/rozenmd/graphql-resolvers/tree/master/api 如果您愿意,我已经在GitHub上编写了一个参考实现: https//github.com/rozenmd/graphql-resolvers/tree/master/api

Typically we'd split out resolvers.js into its own folder, with a file per database Model. 通常我们会将resolvers.js拆分到自己的文件夹中,每个数据库模型都有一个文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM