Show / Hide Table of Contents

Class MappingTemplate

MappingTemplates for AppSync resolvers.

Inheritance
object
MappingTemplate
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()

MappingTemplates for AppSync resolvers.

Methods

DynamoDbDeleteItem(string, string)

Mapping template to delete a single item from a DynamoDB table.

DynamoDbGetItem(string, string, bool?)

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?, bool?)

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(bool?)

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()

MappingTemplates for AppSync resolvers.

protected MappingTemplate()
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])
                  ")
            });

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 string

the name of the hash key field.

idArg string

the name of the Mutation argument.

Returns

MappingTemplate

Remarks

ExampleMetadata: infused

DynamoDbGetItem(string, string, bool?)

Mapping template to get a single item from a DynamoDB table.

public static MappingTemplate DynamoDbGetItem(string keyName, string idArg, bool? consistentRead = null)
Parameters
keyName string

the name of the hash key field.

idArg string

the name of the Query argument.

consistentRead bool?

the name of the hash key field.

Returns

MappingTemplate

Remarks

ExampleMetadata: infused

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

MappingTemplate

Remarks

ExampleMetadata: infused

DynamoDbQuery(KeyCondition, string?, bool?)

Mapping template to query a set of items from a DynamoDB table.

public static MappingTemplate DynamoDbQuery(KeyCondition cond, string? indexName = null, bool? consistentRead = null)
Parameters
cond KeyCondition

the key condition for the query.

indexName string

the key condition for the query.

consistentRead bool?

the key condition for the query.

Returns

MappingTemplate

Remarks

ExampleMetadata: infused

DynamoDbResultItem()

Mapping template for a single result item from DynamoDB.

public static MappingTemplate DynamoDbResultItem()
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

DynamoDbResultList()

Mapping template for a result list from DynamoDB.

public static MappingTemplate DynamoDbResultList()
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

DynamoDbScanTable(bool?)

Mapping template to scan a DynamoDB table to fetch all entries.

public static MappingTemplate DynamoDbScanTable(bool? consistentRead = null)
Parameters
consistentRead bool?
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

FromFile(string)

Create a mapping template from the given file.

public static MappingTemplate FromFile(string fileName)
Parameters
fileName string
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

FromString(string)

Create a mapping template from the given string.

public static MappingTemplate FromString(string template)
Parameters
template string
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

LambdaRequest(string?, string?)

Mapping template to invoke a Lambda function.

public static MappingTemplate LambdaRequest(string? payload = null, string? operation = null)
Parameters
payload string

the VTL template snippet of the payload to send to the lambda.

operation string

the type of operation AppSync should perform on the data source.

Returns

MappingTemplate

Remarks

ExampleMetadata: infused

LambdaResult()

Mapping template to return the Lambda result to the caller.

public static MappingTemplate LambdaResult()
Returns

MappingTemplate

Remarks

ExampleMetadata: infused

RenderTemplate()

this is called to render the mapping template to a VTL string.

public abstract string RenderTemplate()
Returns

string

Remarks

ExampleMetadata: infused

Back to top Generated by DocFX