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 require taking seconds to finish

See original GitHub issue

This piece of code in my structure is taking several seconds in some cases:

console.log('require apollo-server-lambda start');
const { ApolloServer, AuthenticationError } = require('apollo-server-lambda');
console.log('require apollo-server-lambda end');

...Code related to Graphql
const ApolloServerInit = new ApolloServer({
	schema: new GraphQLSchema({
		query: new GraphQLObjectType({
			name: 'RootQueryType',
			fields: schemaObject
		})
	}),
	context: async ({ event, context }) => {
		if(event.source === 'serverless-plugin-warmup') {
			throw new AuthenticationError('Warmup Complete');
		}


		return {
			headers: event.headers,
			functionName: context.functionName,
			event,
			context
		};
	},
	tracing: true,
	engine: { apiKey: process.env.APOLLO_ENGINE_KEY },
	formatError: error => {
		delete error.extensions;
		delete error.path;

		return error;
	},
	playground: process.env.NODE_ENV !== 'production'
});

console.log('Starting ApolloServer');
const apolloServer = ApolloServerInit.createHandler({
	cors: {
		origin: '*',
		credentials: true
	}
});
console.log('Starting ApolloServer');
module.exports = apolloServer

Log from this piece code:

2019-05-24T17:56:26.620Z	a81bfad3-dc95-4f43-ab06-0d7e05a66b68	require apollo-server-lambda start
2019-05-24T17:56:29.744Z	a81bfad3-dc95-4f43-ab06-0d7e05a66b68	require apollo-server-lambda end
...More Logs
2019-05-24T17:56:33.205Z	a81bfad3-dc95-4f43-ab06-0d7e05a66b68	Starting ApolloServer
2019-05-24T17:56:45.305Z	a81bfad3-dc95-4f43-ab06-0d7e05a66b68	End  ApolloServer

I’m using:

  • lambda v8.10
  • apollo-server-lambda v2.5.0
  • graphql v14.3.1
  • graphql-relay v0.6.0

honestly, I have no clue of what can be happening because the issue is not regular. It happens sometimes. The same code some times takes ~400ms sometimes several seconds.

I’ve tried apollo-server-lambda@2.4.8, but the issue remains

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
dsanders11commented, May 28, 2019

honestly, I have no clue of what can be happening because the issue is not regular. It happens sometimes. The same code some times takes ~400ms sometimes several seconds.

@abernix, isn’t this just describing AWS Lambda cold-start behavior? Sounds like what one would expect with Lambda, it’s not a constant performance kind of thing. @luanmuniz, I think this is expected behavior. Look into Lambda “cold starts”. Execution can be quite slow when it hasn’t been used in a while.

Regarding #2674, yes, there’s a regression. I’ll comment on that PR.

1reaction
luanmunizcommented, May 27, 2019

@abernix Just to give you an update. Indeed apollo-server-lambda@2.6.0-alpha.5 doesn’t give me cors problems out of the blue. But I’m still having the original problems with this version

I’m still debugging what’s happening. I will get to you as soon as I have any news! I will try to have something this week

Thanks for the clues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference: ApolloServer - Apollo GraphQL Docs
If you're using a serverless framework integration (such as Lambda), you shouldn't call this method before passing your server into the integration function....
Read more >
Apollo Server plugin event reference - Apollo GraphQL Docs
This reference describes the lifecycle events that your custom Apollo Server plugin can respond to. Apollo Server fires two types of events that...
Read more >
API Reference: ApolloServer - Apollo GraphQL Docs
This API reference documents the ApolloServer class. There are multiple implementations of ApolloServer for different web frameworks with slightly different ...
Read more >
Migrating to Apollo Server 4 - Apollo GraphQL Docs
Apollo Server 4 takes a different approach to integrations by providing a stable web framework integration API, which includes explicit support for serverless ......
Read more >
Subscriptions in Apollo Server - Apollo GraphQL Docs
The subscription server (which we'll instantiate next) doesn't take typeDefs and resolvers options. Instead, it takes an executable GraphQLSchema . We can pass ......
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