Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(appsync): set max batch size when using batch invoke #20995

Merged
merged 7 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export interface BaseResolverProps {
* @default - No caching configuration
*/
readonly cachingConfig?: CachingConfig;
/**
* The maximum number of elements per batch, when using batch invoke
*
* @default - No max batch size
*/
readonly maxBatchSize?: number;
}

/**
Expand Down Expand Up @@ -112,6 +118,7 @@ export class Resolver extends Construct {
requestMappingTemplate: props.requestMappingTemplate ? props.requestMappingTemplate.renderTemplate() : undefined,
responseMappingTemplate: props.responseMappingTemplate ? props.responseMappingTemplate.renderTemplate() : undefined,
cachingConfig: this.createCachingConfig(props.cachingConfig),
maxBatchSize: props.maxBatchSize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be undefined if it's not specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If props.maxBatchSize isn't specified, it would be undefined with the code as is. maxBatchSize: props.maxBatchSize ? props.maxBatchSize : undefined; is redundant, unless there's something I'm missing.

Copy link
Contributor Author

@cponfick cponfick Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealAmazonKendra
You are probably right (I am not too familiar with typescript). I think there is no drawback if it is checked. Actually, it adds some consistency, since other variables are checked as well (line 115 probs.dataSourceName).

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's checked in line 115 because it's setting dataSourceName to props.dataSource.name. In this case, it would throw an error if props.dataSource is undefined.

The whole line: dataSourceName: props.dataSource ? props.dataSource.name : undefined,

That check is just redundant here, like it would be in lines 112-114.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have missed that. I will just revert it, removing the redundant call.

});
props.api.addSchemaDependency(this.resolver);
if (props.dataSource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ describe('Lambda Mapping Templates', () => {
fieldName: 'relatedPosts',
requestMappingTemplate: appsync.MappingTemplate.lambdaRequest('$util.toJson($ctx)', 'BatchInvoke'),
responseMappingTemplate: appsync.MappingTemplate.lambdaResult(),
maxBatchSize: 10,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::Resolver', {
FieldName: 'relatedPosts',
RequestMappingTemplate: batchMT,
MaxBatchSize: 10,
});
});
});
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-appsync/test/integ.appsync-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ lambdaDS.createResolver({
fieldName: 'relatedPosts',
requestMappingTemplate: appsync.MappingTemplate.lambdaRequest(requestPayload('relatedPosts', { withSource: true }), 'BatchInvoke'),
responseMappingTemplate,
maxBatchSize: 5,
cponfick marked this conversation as resolved.
Show resolved Hide resolved
});


Expand Down