class Values
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.AppSync.Values |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsappsync#Values |
![]() | software.amazon.awscdk.services.appsync.Values |
![]() | aws_cdk.aws_appsync.Values |
![]() | aws-cdk-lib » aws_appsync » Values |
Factory class for attribute value assignments.
Example
const api = new appsync.GraphqlApi(this, 'Api', {
name: 'demo',
definition: appsync.Definition.fromFile(path.join(__dirname, 'schema.graphql')),
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.IAM,
},
},
xrayEnabled: true,
});
const demoTable = new dynamodb.Table(this, 'DemoTable', {
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
});
const demoDS = api.addDynamoDbDataSource('demoDataSource', demoTable);
// Resolver for the Query "getDemos" that scans the DynamoDb table and returns the entire list.
// Resolver Mapping Template Reference:
// https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html
demoDS.createResolver('QueryGetDemosResolver', {
typeName: 'Query',
fieldName: 'getDemos',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});
// Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
demoDS.createResolver('MutationAddDemoResolver', {
typeName: 'Mutation',
fieldName: 'addDemo',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem(
appsync.PrimaryKey.partition('id').auto(),
appsync.Values.projecting('input'),
),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});
//To enable DynamoDB read consistency with the `MappingTemplate`:
demoDS.createResolver('QueryGetDemosConsistentResolver', {
typeName: 'Query',
fieldName: 'getDemosConsistent',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(true),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});
Initializer
new Values()
Methods
Name | Description |
---|---|
static attribute(attr) | Allows assigning a value to the specified attribute. |
static projecting(arg?) | Treats the specified object as a map of assignments, where the property names represent attribute names. |
static attribute(attr)
public static attribute(attr: string): AttributeValuesStep
Parameters
- attr
string
Returns
Allows assigning a value to the specified attribute.
static projecting(arg?)
public static projecting(arg?: string): AttributeValues
Parameters
- arg
string
Returns
Treats the specified object as a map of assignments, where the property names represent attribute names.
It’s opinionated about how it represents some of the nested objects: e.g., it will use lists (“L”) rather than sets (“SS”, “NS”, “BS”). By default it projects the argument container ("$ctx.args").