【发布时间】:2018-10-23 10:34:24
【问题描述】:
正在尝试基于https://github.com/serverless/serverless-graphql/blob/master/app-backend/dynamodb/handler.js 创建项目。该代码运行良好,但由于某种原因,我总是收到一条日志警告,告诉我context.done called twice。
import { graphqlLambda, graphiqlLambda, LambdaHandler } from 'apollo-server-lambda'
import lambdaPlayground from 'graphql-playground-middleware-lambda'
import { makeExecutableSchema } from 'graphql-tools'
import { resolvers } from './resolvers'
const typeDefs = require('./schema.gql')
const schema = makeExecutableSchema({ typeDefs, resolvers, logger: console })
export const graphqlHandler: LambdaHandler = async (event, context) => {
const handler = graphqlLambda({ schema })
return handler(event, context, (error: Error | undefined, output: any) => {
output.headers['Access-Control-Allow-Origin'] = '*'
context.done(error, output)
})
}
export const playgroundHandler = lambdaPlayground({
endpoint: '/graphql',
})
export const graphiqlHandler: any = graphiqlLambda({
endpointURL: '/graphql',
})
这段代码给了我以下结果:
Serverless: POST /graphql (λ: graphql)
Serverless: [200] {"statusCode":200,"headers":{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"},"body":"{\"data\":{\"getUserInfo\":\"ads\"}}"}
Serverless: Warning: context.done called twice within handler 'graphql'!
更奇怪的是,如果我评论 context.done 调用,我会得到以下输出(调用按预期停止):
Serverless: POST /graphql (λ: graphql)
Serverless: Warning: context.done called twice within handler 'graphql'!
【问题讨论】:
标签: node.js aws-lambda graphql serverless