question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

apollo-server-lambda with async resolvers callback too early in lambda nodejs10x runtime

See original GitHub issue

We’ve upgrade our lambda runtime to the nodejs10.x (from nodejs8.x). After doing this our resolvers started returning almost immediately without awaiting (e.g. they returned with a body of null).

We had been using the documented way of returning createHandler:

export const handler = server.createHandler({
  cors: { origin: '*' },
});

However now, as a workaround, we’re using (as inspired by #2179):

import { ApolloServer } from 'apollo-server-lambda';
import resolvers from './resources/resolvers';
import typeDefs from './resources/typeDefs';

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: ({ event, context }) => {
    logger.debug(event);
    return { event, context };
  },
});

function runApollo(event, context, apollo) {
  return new Promise((resolve, reject) => {
    const callback = (error, body) => (error ? reject(error) : resolve(body));
    apollo(event, context, callback);
  });
}

export async function handler(event, context) {
  const apollo = server.createHandler({ cors: { origin: '*' } });
  const response = await runApollo(event, context, apollo);
  return response;
}

As an initial diagnostic it looks like the way server.createHandler tries to avoid breaking the previous contract by wrapping its async construction in a sync one no longer works in Node 10.

node: 10.15.3 apollo-server-lambda: 2.4.8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:7

github_iconTop GitHub Comments

3reactions
ryan-marscommented, May 23, 2019

Thank you for posting this. I was up till 4am last night trying to diagnose this issue. I thought it was me.

1reaction
JacksonKearlcommented, Jul 9, 2019

Is this fixed with the closing of awslabs/aws-serverless-express#234?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo server lambda callback function not working on v3.x ...
I m able to hit my /gql end point and getting proper response. but anything inside callbackFilter fn doesn't execute . Do I...
Read more >
Building a serverless GraphQL api with Node.js, AWS Lambda ...
I install both apollo-server and apollo-server-lambda here, because I want to develop most of the time locally and deploy to lambda every ...
Read more >
Top 5 apollo-server-lambda Code Examples - Snyk
To help you get started, we've selected a few apollo-server-lambda examples, based on popular ways it is used in public projects. Secure your...
Read more >
How to Build and Deploy a GraphQL Server in AWS Lambda ...
I am using node 10.x in the examples. You can install the Node version of your choice using asdf. mkdir apollo-server-lambda-nodejs ...
Read more >
Aws lambda with Neo4jGraphQL Async Schema
Turns out because I'd just done too many solutions and got bogged down thinking it was more complicated than it was.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found