Skip to content

Commit 9f42ace

Browse files
author
awstools
committed
feat(client-appsync): Adds support for a new API to evaluate mapping templates with mock data, allowing you to remotely unit test your AppSync resolvers and functions.
1 parent c954e13 commit 9f42ace

File tree

7 files changed

+427
-8
lines changed

7 files changed

+427
-8
lines changed

clients/client-appsync/src/AppSync.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ import {
8484
DisassociateApiCommandInput,
8585
DisassociateApiCommandOutput,
8686
} from "./commands/DisassociateApiCommand";
87+
import {
88+
EvaluateMappingTemplateCommand,
89+
EvaluateMappingTemplateCommandInput,
90+
EvaluateMappingTemplateCommandOutput,
91+
} from "./commands/EvaluateMappingTemplateCommand";
8792
import {
8893
FlushApiCacheCommand,
8994
FlushApiCacheCommandInput,
@@ -772,6 +777,44 @@ export class AppSync extends AppSyncClient {
772777
}
773778
}
774779

780+
/**
781+
* <p>Evaluates a given template and returns the response. The mapping template can be a
782+
* request or response template.</p>
783+
* <p>Request templates take the incoming request after a GraphQL operation is parsed and
784+
* convert it into a request configuration for the selected data source operation. Response
785+
* templates interpret responses from the data source and map it to the shape of the GraphQL
786+
* field output type.</p>
787+
* <p>Mapping templates are written in the Apache Velocity Template Language (VTL).</p>
788+
*/
789+
public evaluateMappingTemplate(
790+
args: EvaluateMappingTemplateCommandInput,
791+
options?: __HttpHandlerOptions
792+
): Promise<EvaluateMappingTemplateCommandOutput>;
793+
public evaluateMappingTemplate(
794+
args: EvaluateMappingTemplateCommandInput,
795+
cb: (err: any, data?: EvaluateMappingTemplateCommandOutput) => void
796+
): void;
797+
public evaluateMappingTemplate(
798+
args: EvaluateMappingTemplateCommandInput,
799+
options: __HttpHandlerOptions,
800+
cb: (err: any, data?: EvaluateMappingTemplateCommandOutput) => void
801+
): void;
802+
public evaluateMappingTemplate(
803+
args: EvaluateMappingTemplateCommandInput,
804+
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: EvaluateMappingTemplateCommandOutput) => void),
805+
cb?: (err: any, data?: EvaluateMappingTemplateCommandOutput) => void
806+
): Promise<EvaluateMappingTemplateCommandOutput> | void {
807+
const command = new EvaluateMappingTemplateCommand(args);
808+
if (typeof optionsOrCb === "function") {
809+
this.send(command, optionsOrCb);
810+
} else if (typeof cb === "function") {
811+
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
812+
this.send(command, optionsOrCb || {}, cb);
813+
} else {
814+
return this.send(command, optionsOrCb);
815+
}
816+
}
817+
775818
/**
776819
* <p>Flushes an <code>ApiCache</code> object.</p>
777820
*/

clients/client-appsync/src/AppSyncClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ import { DeleteGraphqlApiCommandInput, DeleteGraphqlApiCommandOutput } from "./c
7171
import { DeleteResolverCommandInput, DeleteResolverCommandOutput } from "./commands/DeleteResolverCommand";
7272
import { DeleteTypeCommandInput, DeleteTypeCommandOutput } from "./commands/DeleteTypeCommand";
7373
import { DisassociateApiCommandInput, DisassociateApiCommandOutput } from "./commands/DisassociateApiCommand";
74+
import {
75+
EvaluateMappingTemplateCommandInput,
76+
EvaluateMappingTemplateCommandOutput,
77+
} from "./commands/EvaluateMappingTemplateCommand";
7478
import { FlushApiCacheCommandInput, FlushApiCacheCommandOutput } from "./commands/FlushApiCacheCommand";
7579
import { GetApiAssociationCommandInput, GetApiAssociationCommandOutput } from "./commands/GetApiAssociationCommand";
7680
import { GetApiCacheCommandInput, GetApiCacheCommandOutput } from "./commands/GetApiCacheCommand";
@@ -138,6 +142,7 @@ export type ServiceInputTypes =
138142
| DeleteResolverCommandInput
139143
| DeleteTypeCommandInput
140144
| DisassociateApiCommandInput
145+
| EvaluateMappingTemplateCommandInput
141146
| FlushApiCacheCommandInput
142147
| GetApiAssociationCommandInput
143148
| GetApiCacheCommandInput
@@ -189,6 +194,7 @@ export type ServiceOutputTypes =
189194
| DeleteResolverCommandOutput
190195
| DeleteTypeCommandOutput
191196
| DisassociateApiCommandOutput
197+
| EvaluateMappingTemplateCommandOutput
192198
| FlushApiCacheCommandOutput
193199
| GetApiAssociationCommandOutput
194200
| GetApiCacheCommandOutput
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// smithy-typescript generated code
2+
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
3+
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
4+
import { Command as $Command } from "@aws-sdk/smithy-client";
5+
import {
6+
FinalizeHandlerArguments,
7+
Handler,
8+
HandlerExecutionContext,
9+
HttpHandlerOptions as __HttpHandlerOptions,
10+
MetadataBearer as __MetadataBearer,
11+
MiddlewareStack,
12+
SerdeContext as __SerdeContext,
13+
} from "@aws-sdk/types";
14+
15+
import { AppSyncClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../AppSyncClient";
16+
import {
17+
EvaluateMappingTemplateRequest,
18+
EvaluateMappingTemplateRequestFilterSensitiveLog,
19+
EvaluateMappingTemplateResponse,
20+
EvaluateMappingTemplateResponseFilterSensitiveLog,
21+
} from "../models/models_0";
22+
import {
23+
deserializeAws_restJson1EvaluateMappingTemplateCommand,
24+
serializeAws_restJson1EvaluateMappingTemplateCommand,
25+
} from "../protocols/Aws_restJson1";
26+
27+
export interface EvaluateMappingTemplateCommandInput extends EvaluateMappingTemplateRequest {}
28+
export interface EvaluateMappingTemplateCommandOutput extends EvaluateMappingTemplateResponse, __MetadataBearer {}
29+
30+
/**
31+
* <p>Evaluates a given template and returns the response. The mapping template can be a
32+
* request or response template.</p>
33+
* <p>Request templates take the incoming request after a GraphQL operation is parsed and
34+
* convert it into a request configuration for the selected data source operation. Response
35+
* templates interpret responses from the data source and map it to the shape of the GraphQL
36+
* field output type.</p>
37+
* <p>Mapping templates are written in the Apache Velocity Template Language (VTL).</p>
38+
* @example
39+
* Use a bare-bones client and the command you need to make an API call.
40+
* ```javascript
41+
* import { AppSyncClient, EvaluateMappingTemplateCommand } from "@aws-sdk/client-appsync"; // ES Modules import
42+
* // const { AppSyncClient, EvaluateMappingTemplateCommand } = require("@aws-sdk/client-appsync"); // CommonJS import
43+
* const client = new AppSyncClient(config);
44+
* const command = new EvaluateMappingTemplateCommand(input);
45+
* const response = await client.send(command);
46+
* ```
47+
*
48+
* @see {@link EvaluateMappingTemplateCommandInput} for command's `input` shape.
49+
* @see {@link EvaluateMappingTemplateCommandOutput} for command's `response` shape.
50+
* @see {@link AppSyncClientResolvedConfig | config} for AppSyncClient's `config` shape.
51+
*
52+
*/
53+
export class EvaluateMappingTemplateCommand extends $Command<
54+
EvaluateMappingTemplateCommandInput,
55+
EvaluateMappingTemplateCommandOutput,
56+
AppSyncClientResolvedConfig
57+
> {
58+
// Start section: command_properties
59+
// End section: command_properties
60+
61+
constructor(readonly input: EvaluateMappingTemplateCommandInput) {
62+
// Start section: command_constructor
63+
super();
64+
// End section: command_constructor
65+
}
66+
67+
/**
68+
* @internal
69+
*/
70+
resolveMiddleware(
71+
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
72+
configuration: AppSyncClientResolvedConfig,
73+
options?: __HttpHandlerOptions
74+
): Handler<EvaluateMappingTemplateCommandInput, EvaluateMappingTemplateCommandOutput> {
75+
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
76+
77+
const stack = clientStack.concat(this.middlewareStack);
78+
79+
const { logger } = configuration;
80+
const clientName = "AppSyncClient";
81+
const commandName = "EvaluateMappingTemplateCommand";
82+
const handlerExecutionContext: HandlerExecutionContext = {
83+
logger,
84+
clientName,
85+
commandName,
86+
inputFilterSensitiveLog: EvaluateMappingTemplateRequestFilterSensitiveLog,
87+
outputFilterSensitiveLog: EvaluateMappingTemplateResponseFilterSensitiveLog,
88+
};
89+
const { requestHandler } = configuration;
90+
return stack.resolve(
91+
(request: FinalizeHandlerArguments<any>) =>
92+
requestHandler.handle(request.request as __HttpRequest, options || {}),
93+
handlerExecutionContext
94+
);
95+
}
96+
97+
private serialize(input: EvaluateMappingTemplateCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
98+
return serializeAws_restJson1EvaluateMappingTemplateCommand(input, context);
99+
}
100+
101+
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<EvaluateMappingTemplateCommandOutput> {
102+
return deserializeAws_restJson1EvaluateMappingTemplateCommand(output, context);
103+
}
104+
105+
// Start section: command_body_extra
106+
// End section: command_body_extra
107+
}

clients/client-appsync/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from "./DeleteGraphqlApiCommand";
1717
export * from "./DeleteResolverCommand";
1818
export * from "./DeleteTypeCommand";
1919
export * from "./DisassociateApiCommand";
20+
export * from "./EvaluateMappingTemplateCommand";
2021
export * from "./FlushApiCacheCommand";
2122
export * from "./GetApiAssociationCommand";
2223
export * from "./GetApiCacheCommand";

clients/client-appsync/src/models/models_0.ts

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export interface CognitoUserPoolConfig {
113113

114114
/**
115115
* <p>A regular expression for validating the incoming Amazon Cognito user pool app client
116-
* ID.</p>
116+
* ID. If this value isn't set, no filtering is applied.</p>
117117
*/
118118
appIdClientRegex?: string;
119119
}
@@ -1250,7 +1250,7 @@ export interface DomainNameConfig {
12501250
appsyncDomainName?: string;
12511251

12521252
/**
1253-
* <p>The ID of your Amazon Route 53 hosted zone.</p>
1253+
* <p>The ID of your Amazon Route 53 hosted zone.</p>
12541254
*/
12551255
hostedZoneId?: string;
12561256
}
@@ -1551,7 +1551,7 @@ export interface UserPoolConfig {
15511551

15521552
/**
15531553
* <p>A regular expression for validating the incoming Amazon Cognito user pool app client
1554-
* ID.</p>
1554+
* ID. If this value isn't set, no filtering is applied.</p>
15551555
*/
15561556
appIdClientRegex?: string;
15571557
}
@@ -1694,7 +1694,7 @@ export interface CachingConfig {
16941694
* <p>The TTL in seconds for a resolver that has caching activated.</p>
16951695
* <p>Valid values are 1–3,600 seconds.</p>
16961696
*/
1697-
ttl?: number;
1697+
ttl: number | undefined;
16981698

16991699
/**
17001700
* <p>The caching keys for a resolver that has caching activated.</p>
@@ -2057,6 +2057,43 @@ export interface DisassociateApiRequest {
20572057

20582058
export interface DisassociateApiResponse {}
20592059

2060+
export interface EvaluateMappingTemplateRequest {
2061+
/**
2062+
* <p>The mapping template; this can be a request or response template. A
2063+
* <code>template</code> is required for this action.</p>
2064+
*/
2065+
template: string | undefined;
2066+
2067+
/**
2068+
* <p>The map that holds all of the contextual information for your resolver invocation. A
2069+
* <code>context</code> is required for this action.</p>
2070+
*/
2071+
context: string | undefined;
2072+
}
2073+
2074+
/**
2075+
* <p>Contains the list of errors generated when attempting to evaluate a mapping
2076+
* template.</p>
2077+
*/
2078+
export interface ErrorDetail {
2079+
/**
2080+
* <p>The error payload.</p>
2081+
*/
2082+
message?: string;
2083+
}
2084+
2085+
export interface EvaluateMappingTemplateResponse {
2086+
/**
2087+
* <p>The mapping template; this can be a request or response template.</p>
2088+
*/
2089+
evaluationResult?: string;
2090+
2091+
/**
2092+
* <p>The <code>ErrorDetail</code> object.</p>
2093+
*/
2094+
error?: ErrorDetail;
2095+
}
2096+
20602097
/**
20612098
* <p>Represents the input of a <code>FlushApiCache</code> operation.</p>
20622099
*/
@@ -3537,6 +3574,27 @@ export const DisassociateApiResponseFilterSensitiveLog = (obj: DisassociateApiRe
35373574
...obj,
35383575
});
35393576

3577+
/**
3578+
* @internal
3579+
*/
3580+
export const EvaluateMappingTemplateRequestFilterSensitiveLog = (obj: EvaluateMappingTemplateRequest): any => ({
3581+
...obj,
3582+
});
3583+
3584+
/**
3585+
* @internal
3586+
*/
3587+
export const ErrorDetailFilterSensitiveLog = (obj: ErrorDetail): any => ({
3588+
...obj,
3589+
});
3590+
3591+
/**
3592+
* @internal
3593+
*/
3594+
export const EvaluateMappingTemplateResponseFilterSensitiveLog = (obj: EvaluateMappingTemplateResponse): any => ({
3595+
...obj,
3596+
});
3597+
35403598
/**
35413599
* @internal
35423600
*/

0 commit comments

Comments
 (0)