@@ -21,20 +21,50 @@ import { StateMachine, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions';
2121import { Construct } from 'constructs' ;
2222
2323export interface AppSyncDataSourceStepFunctionsExpressProps {
24+ /**
25+ * Id of AppSync GraphQLApi to be associated with the data source.
26+ */
2427 readonly apiId : string ;
2528}
2629
2730export interface CreateStateMachineResolverProps {
31+ /**
32+ * State machine to be called. The state machine type must be EXPRESS.
33+ */
2834 readonly stateMachine : StateMachine ;
29- readonly schema : CfnGraphQLSchema ;
35+ /**
36+ * GraphQL schema to be associated.
37+ * Note: This is only used to add dependency. Omit if you don't manage your schema in CDK.
38+ */
39+ readonly schema ?: CfnGraphQLSchema ;
40+ /**
41+ * Type name for the resolver association e.g. `Query`.
42+ */
3043 readonly typeName : string ;
44+ /**
45+ * Field name for the resolver association e.g. `getPost`.
46+ */
3147 readonly fieldName : string ;
3248}
3349
50+ /**
51+ * A CDK construct to create an AWS AppSync data source to call AWS Step Functions express workflows.
52+ */
3453export class AppSyncDataSourceStepFunctionsExpress extends Construct {
54+ /**
55+ * IAM role to call AWS Step Functions API endpoint for `StartSyncExecution`.
56+ */
3557 readonly role : Role ;
58+ /**
59+ * Data source to call AWS Step Functions API endpoint for `StartSyncExecution`.
60+ */
3661 readonly dataSource : CfnDataSource ;
3762
63+ /**
64+ * @param scope Scope in which this resource is defined.
65+ * @param id Scoped id of the resource.
66+ * @param props Resource properties.
67+ */
3868 constructor ( scope : Construct , id : string , props : AppSyncDataSourceStepFunctionsExpressProps ) {
3969 super ( scope , id ) ;
4070 this . role = new Role ( this , 'ServiceRole' , {
@@ -63,6 +93,11 @@ export class AppSyncDataSourceStepFunctionsExpress extends Construct {
6393 } ) ;
6494 }
6595
96+ /**
97+ * Create a resolver to execute a state machine with a synchronous express workflow
98+ * @param id Scoped id of the resource
99+ * @param props Resource properties
100+ */
66101 createStateMachineResolver ( id : string , props : CreateStateMachineResolverProps ) {
67102 const { stateMachine, schema, typeName, fieldName } = props ;
68103 if ( stateMachine . stateMachineType !== StateMachineType . EXPRESS ) {
@@ -95,7 +130,9 @@ export class AppSyncDataSourceStepFunctionsExpress extends Construct {
95130 $util.parseJson($ctx.result.body).output
96131 ` ,
97132 } ) ;
98- resolver . addDependsOn ( schema ) ;
133+ if ( schema ) {
134+ resolver . addDependsOn ( schema ) ;
135+ }
99136 return resolver ;
100137 }
101138}
0 commit comments