Skip to content

Commit fa8df80

Browse files
committed
chore: add integ task
1 parent a0b8561 commit fa8df80

5 files changed

Lines changed: 98 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ const project = new awscdk.AwsCdkConstructLibrary({
99
packageName: '@opsbr/cdk-appsync-data-source-sfn-express',
1010
license: 'Apache-2.0',
1111
stability: 'experimental',
12+
scripts: {
13+
integ: 'npx cdk deploy --app ./lib/integ.default.js',
14+
},
1215
});
16+
project.addGitIgnore('/cdk.out/');
1317
project.synth();

package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/integ.default.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { RemovalPolicy } from 'aws-cdk-lib';
3+
import { CfnApiKey, CfnGraphQLApi, CfnGraphQLSchema } from 'aws-cdk-lib/aws-appsync';
4+
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
5+
import { Choice, Condition, LogLevel, Pass, StateMachine, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions';
6+
import { AppSyncDataSourceStepFunctionsExpress } from './index';
7+
8+
const app = new cdk.App();
9+
const stack = new cdk.Stack(app, 'IntegAppSyncDataSourceStepFunctionsExpress');
10+
11+
const initializeTask = new Pass(stack, 'Initialize', {
12+
parameters: {
13+
'values.$': '$.values',
14+
'length.$': 'States.ArrayLength($.values)',
15+
'index': 0,
16+
'result': 0,
17+
},
18+
});
19+
const checkIndexTask = new Choice(stack, 'Check index');
20+
const isIndexEqualsToLength = Condition.numberEqualsJsonPath('$.index', '$.length');
21+
const addResultAndIncrementIndexTask = new Pass(stack, 'Add result and increment index', {
22+
parameters: {
23+
'values.$': '$.values',
24+
'length.$': '$.length',
25+
'index.$': 'States.MathAdd($.index, 1)',
26+
'result.$': 'States.MathAdd($.result, States.ArrayGetItem($.values, $.index))',
27+
},
28+
});
29+
const returnTask = new Pass(stack, 'Return', {
30+
outputPath: '$.result',
31+
});
32+
const definition = initializeTask
33+
.next(checkIndexTask
34+
.when(isIndexEqualsToLength, returnTask)
35+
.otherwise(addResultAndIncrementIndexTask.next(checkIndexTask)),
36+
);
37+
38+
const sumStateMachineLogGroup = new LogGroup(stack, 'SumStateMachineLogGroup', {
39+
retention: RetentionDays.ONE_DAY,
40+
removalPolicy: RemovalPolicy.DESTROY,
41+
});
42+
const sumStateMachine = new StateMachine(stack, 'SumStateMachine', {
43+
definition,
44+
stateMachineType: StateMachineType.EXPRESS,
45+
logs: {
46+
destination: sumStateMachineLogGroup,
47+
level: LogLevel.ALL,
48+
includeExecutionData: true,
49+
},
50+
});
51+
52+
const api = new CfnGraphQLApi(stack, 'Api', {
53+
name: 'IntegAppSyncDataSourceStepFunctionsExpress',
54+
authenticationType: 'API_KEY',
55+
});
56+
new CfnApiKey(stack, 'ApiKey', {
57+
apiId: api.attrApiId,
58+
});
59+
60+
const schema = new CfnGraphQLSchema(stack, 'Schema', {
61+
apiId: api.attrApiId,
62+
definition: `
63+
schema {
64+
query: Query
65+
mutation: Mutation
66+
}
67+
type Query {
68+
sum(values: [Int!]!): Int!
69+
}
70+
type Mutation {
71+
sum(values: [Int!]!): Int!
72+
}
73+
`,
74+
});
75+
76+
const sfnExpressDataSource = new AppSyncDataSourceStepFunctionsExpress(stack, 'SfnExpressDataSource', {
77+
apiId: api.attrApiId,
78+
});
79+
sfnExpressDataSource.addStateMachineResolver('SumResolver', {
80+
stateMachine: sumStateMachine,
81+
schema,
82+
typeName: 'Query',
83+
fieldName: 'sum',
84+
});

0 commit comments

Comments
 (0)