@lamware/apollo
v2.0.1
Published
Lamware Middleware for initializing and memoizing Apollo Server in Lambda
Downloads
20
Readme
This Lamware Middleware utilizes the official apollo-server-lambda
package to set-up your Apollo Server outside of the main handler, improving performance.
Installation
This package is available via NPM:
yarn add @lamware/apollo
# or
npm install @lamware/apollo
Usage
import type { APIGatewayProxyHandlerV2 } from 'aws-lambda';
import { ApolloServer } from 'apollo-server-lambda';
import { apollo } from '@lamware/apollo';
import { lamware } from '@lamware/core';
const { handler } = lamware<APIGatewayProxyHandlerV2<any>>()
// You can pass regular Apollo options.
.use(apollo({
introspection: false,
debug: false,
schema: ...,
}))
// You can also pass an entire Apollo Server instance.
.use(apollo(new ApolloServer({
introspection: false,
debug: false,
schema: ...,
})))
// Or even an (a)synchronous closure!
.use(apollo(async () => {
return new ApolloServer({
introspection: false,
debug: false,
schema: ...,
});
}))
.execute(async (payload) => {
return payload.state.apolloHandler(payload);
});
export { handler };