It creates AWS Lambda handler from Falcor's data source.
You can setup a Falcor endpoint on AWS API Gateway and Lambda using serverless-falcor-starter. This project exposes the Falcor endponit using falcor-lambda.
You can create a Lambda handler function. For example:
/* handler.js */
import dataSourceHanlder from "falcor-lambda";
import Router from "falcor-router";
module.exports.handler = dataSourceHanlder(() => new Router([{
route: "greeting",
get: function() {
return { path: ["greeting"], value: "Hello, world" };
}
}]));
Creates a Lambda handler.
sourceCreateFn
: A function which returns a Falcor DataSource.
event
: An event argument of the AWS Lambda function.context
: A context argument of the AWS Lambda function.
debug
: Allows to output debug log.eventToFalcorContext
: This function creates aFalcorContext
object from the Lambda's event or context value. See also Request and event mapping
type FalcorContext: {method: string, jsonGraph?: JSONGraphEnvelope, callPath?: Path, arguments?: any[], pathSuffixes?: Pathset[], paths?: PathSet[]}
FalcorContext
represents Falcor DataSource's get/set/call
arguments.
If you integrate a Lambda handler with AWS API Gateway, you must create a mapping from request to Lambda events with API Request Mapping. falcor-lambda assumes that the request parameter of the GET/POST method will be mapped in the following way:
- GET
"requestTemplates": {
"application/json": {
"method": "$input.params().querystring.method",
"paths": "$util.escapeJavaScript($input.params().querystring.paths)"
}
}
- POST
"requestTemplates": {
"application/json": {
"method": "$input.json('$.method')",
"jsonGraph": "$input.json('$.jsonGraph')",
"callPath": "$input.json('$.callPath')",
"arguments": "$input.json('$.arguments')",
"pathSuffixes": "$input.json('$.pathSuffixes')",
"paths": "$input.json('$.paths')"
}
}
If you want the complete example, please see falcor-lambda-example/falcor/model/s-function.json
By the default, falcor-lambda parses the each value of the event object using JSON.parse
because assumption that they are stringified JSON parameter. If you use other mapping, witch is different from the above sample, you can pass through request values to your DataSource with customizing eventToFalcorContext
.
This software is released under the MIT License, see LICENSE.txt.