apollo-server-lambda with async resolvers callback too early in lambda nodejs10x runtime
See original GitHub issueWe’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:
- Created 4 years ago
- Reactions:16
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for posting this. I was up till 4am last night trying to diagnose this issue. I thought it was me.
Is this fixed with the closing of awslabs/aws-serverless-express#234?