@@ -85,6 +85,7 @@ class ServerlessAppsyncPlugin {
85
85
public readonly commands ?: CommandsDefinition ;
86
86
public readonly configurationVariablesSources ?: VariablesSourcesDefinition ;
87
87
private api ?: Api ;
88
+ private naming ?: Naming ;
88
89
89
90
constructor (
90
91
public serverless : Serverless ,
@@ -344,18 +345,25 @@ class ServerlessAppsyncPlugin {
344
345
}
345
346
346
347
async getApiId ( ) {
348
+ this . loadConfig ( ) ;
349
+
350
+ if ( ! this . naming ) {
351
+ throw new this . serverless . classes . Error (
352
+ 'Could not find the naming service. This should not happen.' ,
353
+ ) ;
354
+ }
355
+
356
+ const logicalIdGraphQLApi = this . naming . getApiLogicalId ( ) ;
357
+
347
358
const { StackResources } = await this . provider . request <
348
359
DescribeStackResourcesInput ,
349
360
DescribeStackResourcesOutput
350
361
> ( 'CloudFormation' , 'describeStackResources' , {
351
362
StackName : this . provider . naming . getStackName ( ) ,
363
+ LogicalResourceId : logicalIdGraphQLApi ,
352
364
} ) ;
353
365
354
- const apiId = last (
355
- StackResources ?. find (
356
- ( resource ) => resource . ResourceType === 'AWS::AppSync::GraphQLApi' ,
357
- ) ?. PhysicalResourceId ?. split ( '/' ) ,
358
- ) ;
366
+ const apiId = last ( StackResources ?. [ 0 ] ?. PhysicalResourceId ?. split ( '/' ) ) ;
359
367
360
368
if ( ! apiId ) {
361
369
throw new this . serverless . classes . Error (
@@ -950,6 +958,7 @@ class ServerlessAppsyncPlugin {
950
958
}
951
959
}
952
960
const config = getAppSyncConfig ( appSync ) ;
961
+ this . naming = new Naming ( appSync . name ) ;
953
962
this . api = new Api ( config , this ) ;
954
963
}
955
964
@@ -992,31 +1001,37 @@ class ServerlessAppsyncPlugin {
992
1001
}
993
1002
994
1003
public resolveVariable : VariableSourceResolver = ( { address } ) => {
995
- const naming = new Naming ( this . serverless . configurationInput . appSync . name ) ;
1004
+ this . loadConfig ( ) ;
1005
+
1006
+ if ( ! this . naming ) {
1007
+ throw new this . serverless . classes . Error (
1008
+ 'Could not find the naming service. This should not happen.' ,
1009
+ ) ;
1010
+ }
996
1011
997
1012
if ( address === 'id' ) {
998
1013
return {
999
1014
value : {
1000
- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'ApiId' ] ,
1015
+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'ApiId' ] ,
1001
1016
} ,
1002
1017
} ;
1003
1018
} else if ( address === 'arn' ) {
1004
1019
return {
1005
1020
value : {
1006
- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'Arn' ] ,
1021
+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'Arn' ] ,
1007
1022
} ,
1008
1023
} ;
1009
1024
} else if ( address === 'url' ) {
1010
1025
return {
1011
1026
value : {
1012
- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'GraphQLUrl' ] ,
1027
+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'GraphQLUrl' ] ,
1013
1028
} ,
1014
1029
} ;
1015
1030
} else if ( address . startsWith ( 'apiKey.' ) ) {
1016
1031
const [ , name ] = address . split ( '.' ) ;
1017
1032
return {
1018
1033
value : {
1019
- 'Fn::GetAtt' : [ naming . getApiKeyLogicalId ( name ) , 'ApiKey' ] ,
1034
+ 'Fn::GetAtt' : [ this . naming . getApiKeyLogicalId ( name ) , 'ApiKey' ] ,
1020
1035
} ,
1021
1036
} ;
1022
1037
} else {
0 commit comments