Skip to content

Commit a2bb44a

Browse files
feat(pipelineFunctions): Added the sync options
1 parent 7d5c65d commit a2bb44a

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

index.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,68 @@ describe('SyncConfig', () => {
16191619
expect(result).toMatchSnapshot();
16201620
});
16211621

1622+
test('Pipeline Resolver Function uses default', () => {
1623+
const apiConfig = {
1624+
...config,
1625+
functionConfigurationsLocation: 'mapping-templates',
1626+
functionConfigurations: [
1627+
{
1628+
dataSource: 'ds',
1629+
name: 'pipeline',
1630+
request: 'request.vtl',
1631+
response: 'response.vtl',
1632+
sync: true,
1633+
},
1634+
],
1635+
};
1636+
1637+
const apiResources = plugin.getFunctionConfigurationResources(apiConfig);
1638+
expect(
1639+
apiResources.GraphQlFunctionConfigurationpipeline.Properties,
1640+
).toHaveProperty('SyncConfig');
1641+
expect(
1642+
apiResources.GraphQlFunctionConfigurationpipeline.Properties.SyncConfig,
1643+
).toEqual({
1644+
ConflictDetection: 'VERSION',
1645+
});
1646+
});
1647+
1648+
test('Pipeline Resolver Function uses advanced config', () => {
1649+
const apiConfig = {
1650+
...config,
1651+
functionConfigurationsLocation: 'mapping-templates',
1652+
functionConfigurations: [
1653+
{
1654+
dataSource: 'ds',
1655+
name: 'pipeline',
1656+
request: 'request.vtl',
1657+
response: 'response.vtl',
1658+
sync: {
1659+
conflictDetection: 'VERSION',
1660+
conflictHandler: 'LAMBDA',
1661+
functionName: 'syncLambda',
1662+
},
1663+
},
1664+
],
1665+
};
1666+
1667+
const apiResources = plugin.getFunctionConfigurationResources(apiConfig);
1668+
expect(
1669+
apiResources.GraphQlFunctionConfigurationpipeline.Properties,
1670+
).toHaveProperty('SyncConfig');
1671+
expect(
1672+
apiResources.GraphQlFunctionConfigurationpipeline.Properties.SyncConfig,
1673+
).toEqual({
1674+
ConflictDetection: 'VERSION',
1675+
ConflictHandler: 'LAMBDA',
1676+
LambdaConflictHandlerConfig: {
1677+
LambdaConflictHandlerArn: {
1678+
'Fn::GetAtt': ['SyncLambdaLambdaFunction', 'Arn'],
1679+
},
1680+
},
1681+
});
1682+
});
1683+
16221684
test('Uses lambda config', () => {
16231685
Object.assign(config, {
16241686
mappingTemplates: [

src/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,25 @@ class ServerlessAppsyncPlugin {
12401240
FunctionVersion: '2018-05-29',
12411241
};
12421242

1243+
if (tpl.sync === true) {
1244+
// Use defaults
1245+
Properties.SyncConfig = {
1246+
ConflictDetection: 'VERSION',
1247+
};
1248+
} else if (typeof tpl.sync === 'object') {
1249+
Properties.SyncConfig = {
1250+
ConflictDetection: tpl.sync.conflictDetection,
1251+
ConflictHandler: tpl.sync.conflictHandler,
1252+
...(tpl.sync.conflictHandler === 'LAMBDA'
1253+
? {
1254+
LambdaConflictHandlerConfig: {
1255+
LambdaConflictHandlerArn: this.getLambdaArn(tpl.sync),
1256+
},
1257+
}
1258+
: {}),
1259+
};
1260+
}
1261+
12431262
if (tpl.maxBatchSize) {
12441263
Properties.MaxBatchSize = tpl.maxBatchSize;
12451264
}

0 commit comments

Comments
 (0)