gpt4 book ai didi

aws-lambda - TypeGraphQl:与 Netlify 函数/AWS Lambda 一起使用

转载 作者:行者123 更新时间:2023-12-05 04:49:39 25 4
gpt4 key购买 nike

经过一天的工作,我终于能够让 TypeQL 与 Netlify Functions/AWS Lambda 一起工作,查看文档和示例,最后绝望的蛮力。

我在这里为其他人分享我的工作代码(或供我自己将来引用 :P ),因为它包含一些违反直觉的关键字用法。

正常方法

我在使用 simple example 时不断遇到错误是:

Your function response must have a numerical statusCode. You gave: $ undefined

当然,我在问题中进行了搜索,但没有一个建议的解决方案对我有用。

最佳答案

工作代码

import 'reflect-metadata'
import { buildSchema } from 'type-graphql'
import { ApolloServer } from 'apollo-server-lambda'
import { RecipeResolver } from 'recipe-resolver'

async function lambdaFunction() {
const schema = await buildSchema({
resolvers: [RecipeResolver],
})

const server = new ApolloServer({
schema,
playground: true,
})

// !!! NOTE: return (await ) server.createHandler() won't work !
exports.handler = server.createHandler()
}

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! NOTE: weird but only way to make it work with
// AWS lambda and netlify functions (netlify dev)
// also needs a reload of the page (first load of playground won't work)
lambdaFunction()
// exports.handler = lambdaFunction wont work
// export { lambdaFunction as handler } wont work
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

我也从简单的例子中得到了一些反射错误

Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for argument named 'title' of 'recipe' of 'RecipeResolver

所以我必须弄清楚如何向@Arg 添加显式类型:

// previous:
// recipe(@Arg('title') title: string)
// fixed:
recipe( @Arg('title', (type) => String) title: string

关于aws-lambda - TypeGraphQl:与 Netlify 函数/AWS Lambda 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67537278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com