Type definition for @aws-appsync/utils
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.
Usage
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';
export function request(ctx) {
const item = ctx.arguments.input;
return ddb.put({ key: { id: util.autoId() }, item });
}
export function response(ctx) {
const { error, result } = ctx;
if (error) {
return util.appendError(error.message, error.type, result);
}
return ctx.result;
}