@forge/cli

14.1.0-next.21-experimental-554d41714.1.0-next.19-experimental-fd0ebbc
out/environment/graphql-client.js
~out/environment/graphql-client.jsModified
+14−20
Index: package/out/environment/graphql-client.js
===================================================================
--- package/out/environment/graphql-client.js
+++ package/out/environment/graphql-client.js
@@ -15,9 +15,9 @@
     constructor(graphqlClient) {
         this.graphqlClient = graphqlClient;
     }
     async createEnvironment(details) {
-        const mutation = `
+        const mutation = (0, cli_shared_1.graphql)(`
       mutation forge_cli_createEnvironment($input: CreateAppEnvironmentInput!) {
         ecosystem {
           createAppEnvironment(input: $input) {
             success
@@ -30,20 +30,18 @@
             }
           }
         }
       }
-    `;
-        const { response: { ecosystem: { createAppEnvironment } }, requestId } = await this.graphqlClient.mutate(mutation, {
+    `);
+        const { response, requestId } = await this.graphqlClient.mutate(mutation, {
             input: {
                 appAri: details.appId,
                 environmentKey: details.environmentKey,
                 environmentType: cli_shared_1.AppEnvironmentType.Development
             }
         });
-        if (!createAppEnvironment) {
-            throw new cli_shared_1.GraphQlMutationError(`Unable to get a response (requestId: ${requestId || 'unknown'})`, { requestId });
-        }
-        const { success, errors } = createAppEnvironment;
+        const { createAppEnvironment } = (0, cli_shared_1.requireMutationPayload)(response.ecosystem, requestId);
+        const { success, errors } = (0, cli_shared_1.requireMutationPayload)(createAppEnvironment, requestId);
         const error = (0, cli_shared_1.getError)(errors);
         if (!success) {
             throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
                 requestId,
@@ -52,9 +50,9 @@
             });
         }
     }
     async getEnvironmentByKey(details) {
-        const query = `
+        const query = (0, cli_shared_1.graphql)(`
       query forge_cli_getEnvironmentByKey($appAri: ID!, $environmentKey: String!) {
         app(id: $appAri) {
           id
           environmentByKey(key: $environmentKey) {
@@ -64,9 +62,9 @@
             type
           }
         }
       }
-    `;
+    `);
         const { app } = await this.graphqlClient.query(query, {
             appAri: details.appId,
             environmentKey: details.environmentKey
         });
@@ -84,9 +82,9 @@
             type: environment.type
         };
     }
     async listEnvironmentPage(details, pageSize = LIST_ENVIRONMENT_PAGE_SIZE) {
-        const query = `
+        const query = (0, cli_shared_1.graphql)(`
       query forge_cli_listEnvironment($id: ID!, $first: Int!, $after: String) {
         app(id: $id) {
           environmentsPage(first: $first, after: $after) {
             nodes {
@@ -108,9 +106,9 @@
             totalCount
           }
         }
       }
-    `;
+    `);
         const { app } = await this.graphqlClient.query(query, {
             id: details.appId,
             first: pageSize,
             after: details.after
@@ -157,9 +155,9 @@
         }
         return results;
     }
     async deleteEnvironment(details) {
-        const mutation = `
+        const mutation = (0, cli_shared_1.graphql)(`
       mutation forge_cli_deleteEnvironment($input: DeleteAppEnvironmentInput!) {
         ecosystem {
           deleteAppEnvironment(input: $input) {
             success
@@ -172,21 +170,17 @@
             }
           }
         }
       }
-    `;
-        const { response: { ecosystem: { deleteAppEnvironment } }, requestId } = await this.graphqlClient.mutate(mutation, {
+    `);
+        const { response, requestId } = await this.graphqlClient.mutate(mutation, {
             input: {
                 appAri: details.appId,
                 environmentKey: details.environmentKey
             }
         });
-        if (!deleteAppEnvironment) {
-            throw new cli_shared_1.GraphQlMutationError(`Unable to get a response (requestId: ${requestId || 'unknown'})`, {
-                requestId
-            });
-        }
-        const { success, errors } = deleteAppEnvironment;
+        const { deleteAppEnvironment } = (0, cli_shared_1.requireMutationPayload)(response.ecosystem, requestId);
+        const { success, errors } = (0, cli_shared_1.requireMutationPayload)(deleteAppEnvironment, requestId);
         const error = (0, cli_shared_1.getError)(errors);
         let errorMessage = error.message;
         if (error.code === exports.APP_HAS_INSTALLATIONS_CODE) {
             errorMessage = cli_shared_1.Text.deleteEnvironment.hasInstallationError(details.environmentKey);