apollo-server-lambda: Cannot read property 'content-type' of undefined

Viewed 238

I'm trying to run a very simple lambda function and testing it locally. But it is throwing me error.

Following is my code

//index.js
const { ApolloServer } = require("apollo-server-lambda");

const server = new ApolloServer({
    typeDefs: `
    type Query {
      greeting: String!
    }
  `,
    resolvers: {
        Query: {
            greeting: () => "Hello!",
        },
    }
});

exports.handler = server.createHandler();

And I'm testing it with lambda-local as following:

//test.js
const lambdaLocal = require('lambda-local');

var jsonPayload = {
    'key': 1,
    'another_key': "Some text"
}

lambdaLocal.execute({
    event: jsonPayload,
    lambdaPath: './index.js',
    profilePath: '~/.aws/credentials',
    profileName: 'default',
    timeoutMs: 3000
}).then(function(done) {
    console.log(done);
}).catch(function(err) {
    console.log(err);
});

But when I run node test.js, I'm getting following error:

"errorMessage": "Cannot read property 'content-type' of undefined",
"errorType": "TypeError",

Additional Information: It works fine if i've following code in index.js without apollo

exports.handler = async(event) => {
    return {
        statusCode: 200,
        body: "Hello"
    }
}

So, this issue is more about apollo-sever-lambda

Can you please help to get me out of this issue? Struggling with it for long time but couldn't resolve it.

Thanks in advance

0 Answers
Related