context.done вызывается дважды в обработчике graphql - PullRequest
0 голосов
/ 13 мая 2018

Попытка создать проект на основе 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'!

1 Ответ

0 голосов
/ 14 мая 2018

Об этом уже сообщалось: https://github.com/dherault/serverless-offline/issues/405

...