Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@jp928/aws-lambda-graphql
Advanced tools
Apollo server for AWS Lambda with WebSocket subscriptions support over API Gateway v1 + v2
⚠️ 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.
📖Documentation for aws-lambda-graphql0.13.0
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.
## API
Server
Creates an Apollo Lambda server.
All options from Apollo Lambda Server and
IConnectionManager
, required
)IEventProcessor
, required
)(err: any) => void
, optional
) - use to log errors from websocket handler on unknown errorISubscriptionManager
, required
)optional
)
onWebsocketConnect(connection: IConnection, event: APIGatewayWebSocketEvent, context: LambdaContext): Promise<boolean|object> | object | boolean
(optional
) - onWebsocketConnect is called when the Websocket connection is initialized ($connect route). Return an object to set a context to your connection object saved in the database e.g. for saving authentication details. This is especially useful to get authentication details (API GW authorizers only run in $connect route)onConnect(messagePayload: object, connection: IConnection, event: APIGatewayWebSocketEvent, context: LambdaContext): Promise<boolean|object> | object | boolean
(optional
) - onConnect is called when the GraphQL connection is initialized (connection_init message). Return an object to set a context to your connection object saved in the database e.g. for saving authentication details. NOTE: This is not the websocket $connect route, see onWebsocketConnect for the $connect route.onOperation(message: OperationRequest, params: ExecutionParams, connection: IConnection): Promise<ExecutionParams>|ExecutionParams
(optional
)onOperationComplete(connection: IConnection, operationId: string): void
(optional
)onDisconnect(connection: IConnection): void
(optional
)optional
) - if connection is not initialized on GraphQL operation, wait for connection to be initialized or throw prohibited connection error. If onConnect
is specified then we wait for initialization otherwise we don't wait. (this is usefull if you're performing authentication in onConnect
).
number
, optional
, default 10
) - how many times should we try to check the connection state?number
, optional
, default 50ms
) - how long should we wait (in milliseconds) until we try to check the connection state again?string
, optional
) - if specified, the connection endpoint will be registered with this value as opposed to extracted from the event payload (as ${domainName}/${stage}
)createHttpHandler()
Creates an AWS Lambda API Gateway v1 handler. Events are handled by apollo-server-lambda
createWebSocketHandler()
Creates an AWS Lambda API Gateway v2 handler that supports GraphQL subscriptions over WebSocket.
createEventHandler()
Creates an AWS Lambda handler for events from events source (for example DynamoDBEventStore). This method internally work with IEventProcessor
.
DynamoDBEventProcessor: IEventProcessor
AWS Lambda DynamoDB stream handler. DynamoDBEventProcessor is used internally by Server.
optional
)(err: any) => void
, optional
)boolean, default: false
) - optional debug mode to add logs in CloudwatchDynamoDBConnectionManager: IConnectionManager
IConnectionManager
implementation that stores information about connections to DynamoDB table, performs communication with them, etc.
Each connection is stored as IConnection
object.
string
, optional
, default: 'Connections'
) - name of DynamoDB table used to store connectionsISubscriptionManager
, required
) - subscription manager used to register subscriptions for connections.number
, optional
, default: 2 hours
)
ttl
field on the row (you are responsible for enabling TTL on given field)boolean,optional,default: false
) - optional debug mode to add logs in CloudwatchDynamoDBEventStore: IEventStore
IEventStore
implemenation that used AWS DynamoDB as storage for published events.
string
, optional
, default: 'Events'
) - events DynamoDB table namenumber
, optional
, default: 2 hours
)
ttl
field on the row (you are responsible for enabling TTL on given field)DynamoDBSubscriptionManager: ISubscriptionManager
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 subscriptionId: RANGE
.
Stores subscription operations to a subscription operations table as subscriptionId: string
. Make sure to set up the key schema as subscriptionId: HASH
.
string
, optional
, default: 'Subscriptions'
)string
, optional
, default: 'SubscriptionOperations'
)number
, optional
, default: 2 hours
)
ttl
field on the row (you are responsible for enabling TTL on given field)function
, optional
, default: '(event: ISubscriptionEvent) => event.event'
)
function
, optional
, default: '(name: string, connection: IConnection) => name'
)
DynamoDBRangeSubscriptionManager: ISubscriptionManager
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 subscriptionId: RANGE
.
Stores subscription operations to a subscription operations table as subscriptionId: string
. Make sure to set up the key schema as subscriptionId: HASH
and event: RANGE
.
string
, optional
, default: 'Subscriptions'
)string
, optional
, default: 'SubscriptionOperations'
)number
, optional
, default: 2 hours
)
ttl
field on the row (you are responsible for enabling TTL on given field)IConnection
IConnectionData
IConnectionData
object
) - connection context data provided from GQL_CONNECTION_INIT
or onConnect
. This data is passed to graphql resolvers' context. All values should be JSON seriablizable.boolean
) - is connection initialized? Basically if you use onConnect
then this value is false
until the onConnect
successfully resolves with non false
value.Context creator function accepts IContext
and returns an object
or Promise
that resolves to an object
.
IContext
Internal context passed to the Context creator function
.
Structure:
IConnection
) - current connection that invoked the execution or is associated with an operationIConnectionManager
)OperationRequest
) - operation associated with current invokationPubSub
) - PubSub instance used by event storeISubscriptionManager
)PubSub
PubSub implementation that publishes events / subscribes to events using underlying event store.
boolean, default: true
) - Serialize event payload to JSONboolean, default: false
) - optional debug mode to add logs in Cloudwatchv1.0.0-alpha.24 - 2021-12-21
FAQs
Apollo server for AWS Lambda with WebSocket subscriptions support over API Gateway v1 + v2
We found that @jp928/aws-lambda-graphql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.