Skip to content

Commit

Permalink
fix: override none,DDB,lambda datasource logical IDs (#8723)
Browse files Browse the repository at this point in the history
* fix: override function datasource logical IDs

* fix: centralize DDB datasource logical ID override

This commit moves the DDB datasource logical ID override to
the core where the other datasources are handled.

* fix: override none datasource logical IDs

Co-authored-by: Colin Ihrig <colihrig@amazon.com>
  • Loading branch information
cjihrig and cjihrig-aws committed Nov 8, 2021
1 parent 81cc461 commit c534dc4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Expand Up @@ -1193,7 +1193,6 @@ export class ModelTransformer extends TransformerModelBase implements Transforme

const cfnDataSource = dataSource.node.defaultChild as CfnDataSource;
cfnDataSource.addDependsOn(role.node.defaultChild as CfnRole);
cfnDataSource.overrideLogicalId(datasourceRoleLogicalID);

if (context.isProjectUsingDataStore()) {
const datasourceDynamoDb = cfnDataSource.dynamoDbConfig as any;
Expand Down
Expand Up @@ -134,7 +134,7 @@ Object {
},
},
"Resources": Object {
"LambdaDataSource4DD51D23": Object {
"LambdaDataSource": Object {
"Properties": Object {
"ApiId": Object {
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
Expand Down Expand Up @@ -1023,15 +1023,15 @@ Object {
},
"convertTextToSpeechFunctionconvertTextToSpeechFunctionAppSyncFunction15BC20B8": Object {
"DependsOn": Array [
"LambdaDataSource4DD51D23",
"LambdaDataSource",
],
"Properties": Object {
"ApiId": Object {
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"DataSourceName": Object {
"Fn::GetAtt": Array [
"LambdaDataSource4DD51D23",
"LambdaDataSource",
"Name",
],
},
Expand Down
18 changes: 15 additions & 3 deletions packages/amplify-graphql-transformer-core/src/transform-host.ts
Expand Up @@ -228,11 +228,15 @@ export class DefaultTransformHost implements TransformHostProvider {
* @param stack Stack to which this datasource needs to mapped to
*/
protected doAddNoneDataSource(id: string, options?: DataSourceOptions, stack?: Stack): NoneDataSource {
return new NoneDataSource(stack ?? this.api, id, {
const ds = new NoneDataSource(stack ?? this.api, id, {
api: this.api,
name: options?.name,
description: options?.description,
});

(ds as any).node.defaultChild.overrideLogicalId(id);

return ds;
}

/**
Expand All @@ -244,13 +248,17 @@ export class DefaultTransformHost implements TransformHostProvider {
* @param stack Stack to which this datasource needs to mapped to
*/
protected doAddDynamoDbDataSource(id: string, table: ITable, options?: DynamoDbDataSourceOptions, stack?: Stack): DynamoDbDataSource {
return new DynamoDbDataSource(stack ?? this.api, id, {
const ds = new DynamoDbDataSource(stack ?? this.api, id, {
api: this.api,
table,
name: options?.name,
description: options?.description,
serviceRole: options?.serviceRole,
});

(ds as any).node.defaultChild.overrideLogicalId(id);

return ds;
}

/**
Expand Down Expand Up @@ -308,11 +316,15 @@ export class DefaultTransformHost implements TransformHostProvider {
* @param options The optional configuration for this data source
*/
protected doAddLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions, stack?: Stack): LambdaDataSource {
return new LambdaDataSource(stack || this.api, id, {
const ds = new LambdaDataSource(stack || this.api, id, {
api: this.api,
lambdaFunction,
name: options?.name,
description: options?.description,
});

(ds as any).node.defaultChild.overrideLogicalId(id);

return ds;
}
}

0 comments on commit c534dc4

Please sign in to comment.