Skip to content

Commit fa2ffa1

Browse files
authored
Merge branch 'main' into corymhall/pipeline-actions/ecr-source
2 parents 9a1c798 + 1187f8c commit fa2ffa1

34 files changed

Lines changed: 779 additions & 981 deletions

packages/@aws-cdk/aws-appsync/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const zone = route53.HostedZone.fromHostedZoneAttributes(this, `HostedZone`, {
330330
new route53.CnameRecord(this, `CnameApiRecord`, {
331331
recordName: 'api',
332332
zone,
333-
domainName: myDomainName,
333+
domainName: api.appSyncDomainName,
334334
});
335335
```
336336

packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ export class GraphqlApi extends GraphqlApiBase {
478478
private schemaResource: CfnGraphQLSchema;
479479
private api: CfnGraphQLApi;
480480
private apiKeyResource?: CfnApiKey;
481+
private domainNameResource?: CfnDomainName;
481482

482483
constructor(scope: Construct, id: string, props: GraphqlApiProps) {
483484
super(scope, id);
@@ -510,18 +511,17 @@ export class GraphqlApi extends GraphqlApiBase {
510511
this.schemaResource = this.schema.bind(this);
511512

512513
if (props.domainName) {
513-
const domainName = new CfnDomainName(this, 'DomainName', {
514+
this.domainNameResource = new CfnDomainName(this, 'DomainName', {
514515
domainName: props.domainName.domainName,
515516
certificateArn: props.domainName.certificate.certificateArn,
516517
description: `domain for ${this.name} at ${this.graphqlUrl}`,
517518
});
518-
519519
const domainNameAssociation = new CfnDomainNameApiAssociation(this, 'DomainAssociation', {
520520
domainName: props.domainName.domainName,
521521
apiId: this.apiId,
522522
});
523523

524-
domainNameAssociation.addDependsOn(domainName);
524+
domainNameAssociation.addDependsOn(this.domainNameResource);
525525
}
526526

527527
if (modes.some((mode) => mode.authorizationType === AuthorizationType.API_KEY)) {
@@ -774,4 +774,15 @@ export class GraphqlApi extends GraphqlApiBase {
774774
public addSubscription(fieldName: string, field: ResolvableField): ObjectType {
775775
return this.schema.addSubscription(fieldName, field);
776776
}
777+
778+
779+
/**
780+
* The AppSyncDomainName of the associated custom domain
781+
*/
782+
public get appSyncDomainName(): string {
783+
if (!this.domainNameResource) {
784+
throw new Error('Cannot retrieve the appSyncDomainName without a domainName configuration');
785+
}
786+
return this.domainNameResource.attrAppSyncDomainName;
787+
}
777788
}

packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,30 @@ describe('Tests of AppSync Domain Name', () => {
4040
},
4141
);
4242
});
43+
44+
test('appSyncDomainName exposes the domain of the associated AWS::AppSync::DomainName', () => {
45+
const api = new appsync.GraphqlApi(stack, 'baseApi', {
46+
name: 'api',
47+
schema: appsync.Schema.fromAsset(
48+
path.join(__dirname, 'appsync.test.graphql'),
49+
),
50+
domainName: {
51+
certificate,
52+
domainName: 'aws.amazon.com',
53+
},
54+
});
55+
56+
expect(stack.resolve(api.appSyncDomainName)).toEqual({ 'Fn::GetAtt': ['baseApiDomainName52E3D63D', 'AppSyncDomainName'] });
57+
});
58+
59+
test('appSyncDomainName should throw an error when no custom domain has been configured', () => {
60+
const api = new appsync.GraphqlApi(stack, 'baseApi', {
61+
name: 'api',
62+
schema: appsync.Schema.fromAsset(
63+
path.join(__dirname, 'appsync.test.graphql'),
64+
),
65+
});
66+
67+
expect(() => api.appSyncDomainName).toThrow('Cannot retrieve the appSyncDomainName without a domainName configuration');
68+
});
4369
});

packages/@aws-cdk/aws-batch/test/batch.integ.snapshot/batch-stack.assets.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)