@@ -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}
0 commit comments