From 9d68f4d39e6859df4a7bd2f191e1b121eb9d933d Mon Sep 17 00:00:00 2001 From: Robert Koch Date: Tue, 3 May 2022 01:42:03 +1000 Subject: [PATCH] fix(appsync): adds dependency for domain name association --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 6 ++- .../aws-appsync/test/appsync-domain.test.ts | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 5d7cce7131cbb..b9328231d3ff7 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -499,16 +499,18 @@ export class GraphqlApi extends GraphqlApiBase { this.schemaResource = this.schema.bind(this); if (props.domainName) { - new CfnDomainName(this, 'DomainName', { + const domainName = new CfnDomainName(this, 'DomainName', { domainName: props.domainName.domainName, certificateArn: props.domainName.certificate.certificateArn, description: `domain for ${this.name} at ${this.graphqlUrl}`, }); - new CfnDomainNameApiAssociation(this, 'DomainAssociation', { + const domainNameAssociation = new CfnDomainNameApiAssociation(this, 'DomainAssociation', { domainName: props.domainName.domainName, apiId: this.apiId, }); + + domainNameAssociation.addDependsOn(domainName); } if (modes.some((mode) => mode.authorizationType === AuthorizationType.API_KEY)) { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts new file mode 100644 index 0000000000000..6e445085e4264 --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts @@ -0,0 +1,43 @@ +import * as path from 'path'; +import { Template } from '@aws-cdk/assertions'; +import * as acm from '@aws-cdk/aws-certificatemanager'; +import { Certificate } from '@aws-cdk/aws-certificatemanager'; +import * as cdk from '@aws-cdk/core'; +import * as appsync from '../lib'; + +// GLOBAL GIVEN +let stack: cdk.Stack; +let certificate: acm.Certificate; + +beforeEach(() => { + stack = new cdk.Stack(); + certificate = new Certificate(stack, 'certificate', { + domainName: 'aws.amazon.com', + }); +}); + +describe('Tests of AppSync Domain Name', () => { + test('DomainNameAssociation depends on DomainName construct', () => { + new appsync.GraphqlApi(stack, 'baseApi', { + name: 'api', + schema: appsync.Schema.fromAsset( + path.join(__dirname, 'appsync.test.graphql'), + ), + domainName: { + certificate, + domainName: 'aws.amazon.com', + }, + }); + + const domainName = Template.fromStack(stack).findResources( + 'AWS::AppSync::DomainName', + ); + + Template.fromStack(stack).hasResource( + 'AWS::AppSync::DomainNameApiAssociation', + { + DependsOn: [Object.keys(domainName)[0]], + }, + ); + }); +});