@@ -85,6 +85,7 @@ class ServerlessAppsyncPlugin {
8585 public readonly commands ?: CommandsDefinition ;
8686 public readonly configurationVariablesSources ?: VariablesSourcesDefinition ;
8787 private api ?: Api ;
88+ private naming ?: Naming ;
8889
8990 constructor (
9091 public serverless : Serverless ,
@@ -344,18 +345,25 @@ class ServerlessAppsyncPlugin {
344345 }
345346
346347 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+
347358 const { StackResources } = await this . provider . request <
348359 DescribeStackResourcesInput ,
349360 DescribeStackResourcesOutput
350361 > ( 'CloudFormation' , 'describeStackResources' , {
351362 StackName : this . provider . naming . getStackName ( ) ,
363+ LogicalResourceId : logicalIdGraphQLApi ,
352364 } ) ;
353365
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 ( '/' ) ) ;
359367
360368 if ( ! apiId ) {
361369 throw new this . serverless . classes . Error (
@@ -950,6 +958,7 @@ class ServerlessAppsyncPlugin {
950958 }
951959 }
952960 const config = getAppSyncConfig ( appSync ) ;
961+ this . naming = new Naming ( appSync . name ) ;
953962 this . api = new Api ( config , this ) ;
954963 }
955964
@@ -992,31 +1001,37 @@ class ServerlessAppsyncPlugin {
9921001 }
9931002
9941003 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+ }
9961011
9971012 if ( address === 'id' ) {
9981013 return {
9991014 value : {
1000- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'ApiId' ] ,
1015+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'ApiId' ] ,
10011016 } ,
10021017 } ;
10031018 } else if ( address === 'arn' ) {
10041019 return {
10051020 value : {
1006- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'Arn' ] ,
1021+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'Arn' ] ,
10071022 } ,
10081023 } ;
10091024 } else if ( address === 'url' ) {
10101025 return {
10111026 value : {
1012- 'Fn::GetAtt' : [ naming . getApiLogicalId ( ) , 'GraphQLUrl' ] ,
1027+ 'Fn::GetAtt' : [ this . naming . getApiLogicalId ( ) , 'GraphQLUrl' ] ,
10131028 } ,
10141029 } ;
10151030 } else if ( address . startsWith ( 'apiKey.' ) ) {
10161031 const [ , name ] = address . split ( '.' ) ;
10171032 return {
10181033 value : {
1019- 'Fn::GetAtt' : [ naming . getApiKeyLogicalId ( name ) , 'ApiKey' ] ,
1034+ 'Fn::GetAtt' : [ this . naming . getApiKeyLogicalId ( name ) , 'ApiKey' ] ,
10201035 } ,
10211036 } ;
10221037 } else {
0 commit comments