Class MappingTemplate
MappingTemplates for AppSync resolvers.
Inheritance
Namespace: Amazon.CDK.AWS.AppSync
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class MappingTemplate : DeputyBase
Syntax (vb)
Public MustInherit Class MappingTemplate
Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
// Build a data source for AppSync to access the database.
GraphqlApi api;
// Create username and password secret for DB Cluster
var secret = new DatabaseSecret(this, "AuroraSecret", new DatabaseSecretProps {
Username = "clusteradmin"
});
// The VPC to place the cluster in
var vpc = new Vpc(this, "AuroraVpc");
// Create the serverless cluster, provide all values needed to customise the database.
var cluster = new ServerlessCluster(this, "AuroraCluster", new ServerlessClusterProps {
Engine = DatabaseClusterEngine.AURORA_MYSQL,
Vpc = vpc,
Credentials = new Dictionary<string, string> { { "username", "clusteradmin" } },
ClusterIdentifier = "db-endpoint-test",
DefaultDatabaseName = "demos"
});
var rdsDS = api.AddRdsDataSource("rds", cluster, secret, "demos");
// Set up a resolver for an RDS query.
rdsDS.CreateResolver("QueryGetDemosRdsResolver", new BaseResolverProps {
TypeName = "Query",
FieldName = "getDemosRds",
RequestMappingTemplate = MappingTemplate.FromString(@"
{
""version"": ""2018-05-29"",
""statements"": [
""SELECT * FROM demos""
]
}
"),
ResponseMappingTemplate = MappingTemplate.FromString(@"
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
")
});
// Set up a resolver for an RDS mutation.
rdsDS.CreateResolver("MutationAddDemoRdsResolver", new BaseResolverProps {
TypeName = "Mutation",
FieldName = "addDemoRds",
RequestMappingTemplate = MappingTemplate.FromString(@"
{
""version"": ""2018-05-29"",
""statements"": [
""INSERT INTO demos VALUES (:id, :version)"",
""SELECT * WHERE id = :id""
],
""variableMap"": {
"":id"": $util.toJson($util.autoId()),
"":version"": $util.toJson($ctx.args.version)
}
}
"),
ResponseMappingTemplate = MappingTemplate.FromString(@"
$utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
")
});
Synopsis
Constructors
MappingTemplate() | |
MappingTemplate(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
MappingTemplate(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
DynamoDbDeleteItem(String, String) | Mapping template to delete a single item from a DynamoDB table. |
DynamoDbGetItem(String, String, Nullable<Boolean>) | Mapping template to get a single item from a DynamoDB table. |
DynamoDbPutItem(PrimaryKey, AttributeValues) | Mapping template to save a single item to a DynamoDB table. |
DynamoDbQuery(KeyCondition, String, Nullable<Boolean>) | Mapping template to query a set of items from a DynamoDB table. |
DynamoDbResultItem() | Mapping template for a single result item from DynamoDB. |
DynamoDbResultList() | Mapping template for a result list from DynamoDB. |
DynamoDbScanTable(Nullable<Boolean>) | Mapping template to scan a DynamoDB table to fetch all entries. |
FromFile(String) | Create a mapping template from the given file. |
FromString(String) | Create a mapping template from the given string. |
LambdaRequest(String, String) | Mapping template to invoke a Lambda function. |
LambdaResult() | Mapping template to return the Lambda result to the caller. |
RenderTemplate() | this is called to render the mapping template to a VTL string. |
Constructors
MappingTemplate()
protected MappingTemplate()
MappingTemplate(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected MappingTemplate(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
MappingTemplate(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected MappingTemplate(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
DynamoDbDeleteItem(String, String)
Mapping template to delete a single item from a DynamoDB table.
public static MappingTemplate DynamoDbDeleteItem(string keyName, string idArg)
Parameters
- keyName System.String
the name of the hash key field.
- idArg System.String
the name of the Mutation argument.
Returns
DynamoDbGetItem(String, String, Nullable<Boolean>)
Mapping template to get a single item from a DynamoDB table.
public static MappingTemplate DynamoDbGetItem(string keyName, string idArg, Nullable<bool> consistentRead = null)
Parameters
- keyName System.String
the name of the hash key field.
- idArg System.String
the name of the Query argument.
- consistentRead System.Nullable<System.Boolean>
the name of the hash key field.
Returns
DynamoDbPutItem(PrimaryKey, AttributeValues)
Mapping template to save a single item to a DynamoDB table.
public static MappingTemplate DynamoDbPutItem(PrimaryKey key, AttributeValues values)
Parameters
- key PrimaryKey
the assigment of Mutation values to the primary key.
- values AttributeValues
the assignment of Mutation values to the table attributes.
Returns
DynamoDbQuery(KeyCondition, String, Nullable<Boolean>)
Mapping template to query a set of items from a DynamoDB table.
public static MappingTemplate DynamoDbQuery(KeyCondition cond, string indexName = null, Nullable<bool> consistentRead = null)
Parameters
- cond KeyCondition
the key condition for the query.
- indexName System.String
the key condition for the query.
- consistentRead System.Nullable<System.Boolean>
the key condition for the query.
Returns
DynamoDbResultItem()
Mapping template for a single result item from DynamoDB.
public static MappingTemplate DynamoDbResultItem()
Returns
DynamoDbResultList()
Mapping template for a result list from DynamoDB.
public static MappingTemplate DynamoDbResultList()
Returns
DynamoDbScanTable(Nullable<Boolean>)
Mapping template to scan a DynamoDB table to fetch all entries.
public static MappingTemplate DynamoDbScanTable(Nullable<bool> consistentRead = null)
Parameters
- consistentRead System.Nullable<System.Boolean>
Returns
FromFile(String)
Create a mapping template from the given file.
public static MappingTemplate FromFile(string fileName)
Parameters
- fileName System.String
Returns
FromString(String)
Create a mapping template from the given string.
public static MappingTemplate FromString(string template)
Parameters
- template System.String
Returns
LambdaRequest(String, String)
Mapping template to invoke a Lambda function.
public static MappingTemplate LambdaRequest(string payload = null, string operation = null)
Parameters
- payload System.String
the VTL template snippet of the payload to send to the lambda.
- operation System.String
the type of operation AppSync should perform on the data source.
Returns
LambdaResult()
Mapping template to return the Lambda result to the caller.
public static MappingTemplate LambdaResult()
Returns
RenderTemplate()
this is called to render the mapping template to a VTL string.
public abstract string RenderTemplate()
Returns
System.String