Skip to content

Commit

Permalink
feat(graphql): make VTL for different datasources possible
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegertn committed May 5, 2021
1 parent 7fceb2a commit d25be7f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/constructs/graphql-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ export class GraphQlApi extends cdk.Construct {
}

public addDynamoDbVtlResolver<TYPE extends { __typename?: any }>(typeName: TYPE['__typename'], fieldName: keyof Omit<TYPE, '__typename'>): void {
if (!this.tableDataSource) {
throw new Error('DynamoDB is not initialized');
}
this.addVtlResolver(typeName, fieldName, this.tableDataSource);
}

public addVtlResolver<TYPE extends { __typename?: any }>(typeName: TYPE['__typename'], fieldName: keyof Omit<TYPE, '__typename'>, dataSource: appsync.BaseDataSource): void {
const operationId = `${typeName}.${fieldName}`;

const mappingReqFile = `./src/vtl/${operationId}.req.vm`;
Expand All @@ -244,7 +251,7 @@ export class GraphQlApi extends cdk.Construct {
api: this.api,
typeName,
fieldName: fieldName as string,
dataSource: this.tableDataSource,
dataSource,
requestMappingTemplate: appsync.MappingTemplate.fromFile(mappingReqFile),
responseMappingTemplate: appsync.MappingTemplate.fromFile(mappingResFile),
});
Expand Down

0 comments on commit d25be7f

Please sign in to comment.