Repository: sid88in/serverless-appsync-plugin (ts)

Issue:
v2.3.0 Update Drops/Recreates API
I just reproduced something I saw on one of my test APIs - updating this library to v2.3.0 will cause your API to be deleted/recreated. This gives it a new ApiId, URL, the works. I don't think this was intended. For any folks who are sharing the ApiId as a string/constant, this will wreck them.

![image](https://github.com/sid88in/serverless-appsync-plugin/assets/1322700/96149eda-6ea0-4b87-aae1-8e61bf879baa)
![image](https://github.com/sid88in/serverless-appsync-plugin/assets/1322700/d869eba1-1905-46ad-8619-9e126d0b7074)

As a side note, my project with a Merged API was saved from this because, evidently, you cannot delete a source API if it is used by a Merged. That saved my bacon.
![image](https://github.com/sid88in/serverless-appsync-plugin/assets/1322700/d5fdd5b5-d57a-4b00-a427-4e258d5b379b)


Pull request description:
fix: only set visibility when specified explicitly
Fixes #607 



Patch:
diff --git a/doc/general-config.md b/doc/general-config.md
index 26e7990..e91972d 100644
--- a/doc/general-config.md
+++ b/doc/general-config.md
@@ -49,7 +49,7 @@ appSync:
 - `waf`: See [Web Application Firefall](WAF.md)
 - `logging`: See [Logging](#Logging)
 - `xrayEnabled`: Boolean. Enable or disable X-Ray tracing.
-- `visibility`: Optional. `GLOBAL` or `PRIVATE`. Defaults to `GLOBAL`.
+- `visibility`: Optional. `GLOBAL` or `PRIVATE`. **Changing this value requires the replacement of the API.**
 - `tags`: A key-value pair for tagging this AppSync API
 
 ## Schema
diff --git a/src/resources/Api.ts b/src/resources/Api.ts
index c1ea0a2..95e4192 100644
--- a/src/resources/Api.ts
+++ b/src/resources/Api.ts
@@ -74,7 +74,6 @@ export class Api {
       Type: 'AWS::AppSync::GraphQLApi',
       Properties: {
         Name: this.config.name,
-        Visibility: this.config.visibility || 'GLOBAL',
         XrayEnabled: this.config.xrayEnabled || false,
         Tags: this.getTagsConfig(),
       },
@@ -106,6 +105,12 @@ export class Api {
       });
     }
 
+    if (this.config.visibility) {
+      merge(endpointResource.Properties, {
+        Visibility: this.config.visibility,
+      });
+    }
+
     const resources = {
       [logicalId]: endpointResource,
     };


Test patch:
diff --git a/src/__tests__/__snapshots__/api.test.ts.snap b/src/__tests__/__snapshots__/api.test.ts.snap
index b160f5a..37d4314 100644
--- a/src/__tests__/__snapshots__/api.test.ts.snap
+++ b/src/__tests__/__snapshots__/api.test.ts.snap
@@ -27,7 +27,6 @@ Object {
           "Value": "Dev",
         },
       ],
-      "Visibility": "GLOBAL",
       "XrayEnabled": false,
     },
     "Type": "AWS::AppSync::GraphQLApi",
@@ -65,7 +64,6 @@ Object {
           "Value": "Dev",
         },
       ],
-      "Visibility": "GLOBAL",
       "XrayEnabled": false,
     },
     "Type": "AWS::AppSync::GraphQLApi",
diff --git a/src/__tests__/api.test.ts b/src/__tests__/api.test.ts
index 28cba2d..c8389f1 100644
--- a/src/__tests__/api.test.ts
+++ b/src/__tests__/api.test.ts
@@ -22,7 +22,6 @@ describe('Api', () => {
                   "Value": "Dev",
                 },
               ],
-              "Visibility": "GLOBAL",
               "XrayEnabled": false,
             },
             "Type": "AWS::AppSync::GraphQLApi",
@@ -92,7 +91,6 @@ describe('Api', () => {
                   "Value": "Dev",
                 },
               ],
-              "Visibility": "GLOBAL",
               "XrayEnabled": false,
             },
             "Type": "AWS::AppSync::GraphQLApi",
@@ -198,7 +196,6 @@ describe('Api', () => {
                 "DefaultAction": "ALLOW",
                 "UserPoolId": "pool123",
               },
-              "Visibility": "GLOBAL",
               "XrayEnabled": false,
             },
             "Type": "AWS::AppSync::GraphQLApi",