@@ -24,11 +24,11 @@ const testSchema = /* GraphQL */ `
2424 }
2525` ;
2626
27- const createStackAndSetContext = ( ) : Stack => {
27+ const createStackAndSetContext = ( backendType : 'sandbox' | 'branch' ) : Stack => {
2828 const app = new App ( ) ;
2929 app . node . setContext ( 'amplify-backend-name' , 'testEnvName' ) ;
3030 app . node . setContext ( 'amplify-backend-namespace' , 'testBackendId' ) ;
31- app . node . setContext ( 'amplify-backend-type' , 'branch' ) ;
31+ app . node . setContext ( 'amplify-backend-type' , backendType ) ;
3232 const stack = new Stack ( app ) ;
3333 return stack ;
3434} ;
@@ -60,13 +60,13 @@ void describe('defaultJsResolverCode', () => {
6060 } ) ;
6161} ) ;
6262
63- void describe ( 'convertJsResolverDefinition' , ( ) => {
63+ void describe ( 'convertJsResolverDefinition - branch deployment ' , ( ) => {
6464 let stack : Stack ;
6565 let amplifyApi : AmplifyData ;
6666 const authorizationModes = { apiKeyConfig : { expires : Duration . days ( 7 ) } } ;
6767
6868 void beforeEach ( ( ) => {
69- stack = createStackAndSetContext ( ) ;
69+ stack = createStackAndSetContext ( 'branch' ) ;
7070 amplifyApi = new AmplifyData ( stack , 'amplifyData' , {
7171 apiName : 'amplifyData' ,
7272 definition : AmplifyDataDefinition . fromString ( testSchema ) ,
@@ -191,6 +191,69 @@ void describe('convertJsResolverDefinition', () => {
191191 template . resourceCountIs ( 'AWS::AppSync::Resolver' , 1 ) ;
192192 } ) ;
193193
194+ void it ( 'adds api id and environment name to stash for non-sandbox deployment' , ( ) => {
195+ const absolutePath = resolve (
196+ fileURLToPath ( import . meta. url ) ,
197+ '../../lib/assets' ,
198+ 'js_resolver_handler.js' ,
199+ ) ;
200+
201+ const schema = a . schema ( {
202+ customQuery : a
203+ . query ( )
204+ . authorization ( ( allow ) => allow . publicApiKey ( ) )
205+ . returns ( a . string ( ) )
206+ . handler (
207+ a . handler . custom ( {
208+ entry : absolutePath ,
209+ } ) ,
210+ ) ,
211+ } ) ;
212+ const { jsFunctions } = schema . transform ( ) ;
213+ convertJsResolverDefinition ( stack , amplifyApi , jsFunctions ) ;
214+
215+ const template = Template . fromStack ( stack ) ;
216+ template . hasResourceProperties ( 'AWS::AppSync::Resolver' , {
217+ Runtime : {
218+ Name : 'APPSYNC_JS' ,
219+ RuntimeVersion : '1.0.0' ,
220+ } ,
221+ Kind : 'PIPELINE' ,
222+ TypeName : 'Query' ,
223+ FieldName : 'customQuery' ,
224+ Code : {
225+ 'Fn::Join' : [
226+ '' ,
227+ [
228+ "/**\n * Pipeline resolver request handler\n */\nexport const request = (ctx) => {\n ctx.stash.awsAppsyncApiId = '" ,
229+ {
230+ 'Fn::GetAtt' : [
231+ Match . stringLikeRegexp ( 'amplifyDataGraphQLAPI.*' ) ,
232+ 'ApiId' ,
233+ ] ,
234+ } ,
235+ "';\n ctx.stash.amplifyApiEnvironmentName = 'testEnvName';\n return {};\n};\n/**\n * Pipeline resolver response handler\n */\nexport const response = (ctx) => {\n return ctx.prev.result;\n};\n" ,
236+ ] ,
237+ ] ,
238+ } ,
239+ } ) ;
240+ } ) ;
241+ } ) ;
242+
243+ void describe ( 'convertJsResolverDefinition - sandbox deployment' , ( ) => {
244+ let stack : Stack ;
245+ let amplifyApi : AmplifyData ;
246+ const authorizationModes = { apiKeyConfig : { expires : Duration . days ( 7 ) } } ;
247+
248+ void beforeEach ( ( ) => {
249+ stack = createStackAndSetContext ( 'sandbox' ) ;
250+ amplifyApi = new AmplifyData ( stack , 'amplifyData' , {
251+ apiName : 'amplifyData' ,
252+ definition : AmplifyDataDefinition . fromString ( testSchema ) ,
253+ authorizationModes,
254+ } ) ;
255+ } ) ;
256+
194257 void it ( 'adds api id and environment name to stash' , ( ) => {
195258 const absolutePath = resolve (
196259 fileURLToPath ( import . meta. url ) ,
0 commit comments