This project contains utility function definitions and type definitions for working with AWS AppSync Resolvers written in JavaScript using the APPSYNC_JS runtime. This includes the util
and extensions
utilities. For more information on these utilities, see the AppSync documentation.
Install the type definition by running
npm install @aws-appsync/utils
In your AppSync function code definition:
import { util } from '@aws-appsync/utils';
import * as ddb from '@aws-appsync/utils/dynamodb';
/**
* Creates a new item in a DynamoDB table
* @param ctx contextual information about the request
*/
export function request(ctx) {
const item = ctx.arguments.input;
return ddb.put({ key: { id: util.autoId() }, item });
}
/**
* Returns the result
* @param ctx contextual information about the request
*/
export function response(ctx) {
const { error, result } = ctx;
if (error) {
return util.appendError(error.message, error.type, result);
}
return ctx.result;
}