经过一天的工作,我终于能够让TypeQL与Netlify Functions / AWS Lambda一起工作,查看了文档和示例,最后不顾一切地使用蛮力。
我在这里将我的工作代码分享给其他人(或者供我自己的将来参考:P ),因为它包含了一些违反直觉的关键字用法。
普通方法
在使用simple example时,我不断得到的错误是:
Your function response must have a numerical statusCode. You gave: $ undefined我当然在问题中进行了搜索,但没有一个建议的解决方案对我有效。
发布于 2021-05-14 23:57:37
工作代码
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: stringhttps://stackoverflow.com/questions/67537278
复制相似问题