Skip to content

Commit

Permalink
feat(pipelineFunctions): Added the sync options
Browse files Browse the repository at this point in the history
  • Loading branch information
arielschvartz authored Jul 8, 2022
1 parent 7d5c65d commit a2bb44a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
62 changes: 62 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,68 @@ describe('SyncConfig', () => {
expect(result).toMatchSnapshot();
});

test('Pipeline Resolver Function uses default', () => {
const apiConfig = {
...config,
functionConfigurationsLocation: 'mapping-templates',
functionConfigurations: [
{
dataSource: 'ds',
name: 'pipeline',
request: 'request.vtl',
response: 'response.vtl',
sync: true,
},
],
};

const apiResources = plugin.getFunctionConfigurationResources(apiConfig);
expect(
apiResources.GraphQlFunctionConfigurationpipeline.Properties,
).toHaveProperty('SyncConfig');
expect(
apiResources.GraphQlFunctionConfigurationpipeline.Properties.SyncConfig,
).toEqual({
ConflictDetection: 'VERSION',
});
});

test('Pipeline Resolver Function uses advanced config', () => {
const apiConfig = {
...config,
functionConfigurationsLocation: 'mapping-templates',
functionConfigurations: [
{
dataSource: 'ds',
name: 'pipeline',
request: 'request.vtl',
response: 'response.vtl',
sync: {
conflictDetection: 'VERSION',
conflictHandler: 'LAMBDA',
functionName: 'syncLambda',
},
},
],
};

const apiResources = plugin.getFunctionConfigurationResources(apiConfig);
expect(
apiResources.GraphQlFunctionConfigurationpipeline.Properties,
).toHaveProperty('SyncConfig');
expect(
apiResources.GraphQlFunctionConfigurationpipeline.Properties.SyncConfig,
).toEqual({
ConflictDetection: 'VERSION',
ConflictHandler: 'LAMBDA',
LambdaConflictHandlerConfig: {
LambdaConflictHandlerArn: {
'Fn::GetAtt': ['SyncLambdaLambdaFunction', 'Arn'],
},
},
});
});

test('Uses lambda config', () => {
Object.assign(config, {
mappingTemplates: [
Expand Down
19 changes: 19 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,25 @@ class ServerlessAppsyncPlugin {
FunctionVersion: '2018-05-29',
};

if (tpl.sync === true) {
// Use defaults
Properties.SyncConfig = {
ConflictDetection: 'VERSION',
};
} else if (typeof tpl.sync === 'object') {
Properties.SyncConfig = {
ConflictDetection: tpl.sync.conflictDetection,
ConflictHandler: tpl.sync.conflictHandler,
...(tpl.sync.conflictHandler === 'LAMBDA'
? {
LambdaConflictHandlerConfig: {
LambdaConflictHandlerArn: this.getLambdaArn(tpl.sync),
},
}
: {}),
};
}

if (tpl.maxBatchSize) {
Properties.MaxBatchSize = tpl.maxBatchSize;
}
Expand Down

0 comments on commit a2bb44a

Please sign in to comment.