⚠️ This documentation is currently for 1.0.0-alpha.X package which supports only subscriptions-transport-ws and drops the legacy protocol and client support! To use old version that supports legacy protocol and client see the link 0.13.0 below.
Use Apollo Server Lambda with GraphQL subscriptions over WebSocket (AWS API Gateway v2).
With this library you can do:
yarn add aws-lambda-graphql graphql graphql-subscriptions # or npm install aws-lamda-graphql graphql graphql-subscriptions
There is a quick start guide.
Creates an Apollo Lambda server.
All options from Apollo Lambda Server and
(err: any) => void,
optional) - use to log errors from websocket handler on unknown error
onConnect(messagePayload: object, connection: IConnection, event: APIGatewayWebSocketEvent, context: LambdaContext): Promise<boolean|object> | object | boolean(
optional) - Return an object to set a context to your connection object saved in the database e.g. for saving authentication details
onOperation(message: OperationRequest, params: ExecutionParams, connection: IConnection): Promise<ExecutionParams>|ExecutionParams(
onOperationComplete(connection: IConnection, operationId: string): void(
onDisconnect(connection: IConnection): void(
optional) - if connection is not initialised on GraphQL operation, wait for connection to be initialised or throw prohibited connection error. If
onConnectis specified then we wait for initialisation otherwise we don't wait. (this is usefull if you're performing authentication in
default 10) - how many times should we try to check the connection state?
default 50ms) - how long should we wait (in milliseconds) until we try to check the connection state again?
Creates an AWS Lambda API Gateway v1 handler. Events are handled by apollo-server-lambda
Creates an AWS Lambda API Gateway v2 handler that supports GraphQL subscriptions over WebSocket.
Creates an AWS Lambda handler for events from events source (for example DynamoDBEventStore). This method internally work with
AWS Lambda DynamoDB stream handler. DynamoDBEventProcessor is used internally by Server.
(err: any) => void,
IConnectionManager implementation that stores information about connections to DynamoDB table, performs communication with them, etc.
Each connection is stored as
default: 'Connections') - name of DynamoDB table used to store connections
required) - subscription manager used to register subscriptions for connections.
IEventStore implemenation that used AWS DynamoDB as storage for published events.
default: 'Events') - events DynamoDB table name
default: 2 hours)
ttlfield on the row (you are responsible for enabling TTL on given field)
ISubscriptionManager implementation that used AWS DynamoDB as storage for subscriptions.
Stores subscriptions to a subscriptions table as
event: string and
subscriptionId: string.Make sure to set up the key schema as
event: HASH and
Stores subscription operations to a subscription operations table as
subscriptionId: string. Make sure to set up the key schema as
object) - connection context data provided from
onConnect. This data is passed to graphql resolvers' context. All values should be JSON seriablizable.
boolean) - is connection initialised? Basically if you use
onConnectthen this value is
onConnectsuccessfully resolves with non
Context creator function accepts
IContext and returns an
Promise that resolves to an
Internal context passed to the
Context creator function.
IConnection) - current connection that invoked the execution or is associated with an operation
OperationRequest) - operation associated with current invokation
PubSub) - PubSub instance used by event store
PubSub implementation that publishes events / subscribes to events using underlying event store.