@forge/cli
12.11.012.12.0-next.9
out/environment/graphql-client.jsout/environment/graphql-client.js+76−18
Index: package/out/environment/graphql-client.js
===================================================================
--- package/out/environment/graphql-client.js
+++ package/out/environment/graphql-client.js
@@ -1,12 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.GraphqlClient = exports.MissingAppError = exports.APP_HAS_INSTALLATIONS_CODE = void 0;
+exports.GraphqlClient = exports.EnvironmentNotFoundError = exports.MissingAppError = exports.APP_HAS_INSTALLATIONS_CODE = void 0;
const cli_shared_1 = require("@forge/cli-shared");
exports.APP_HAS_INSTALLATIONS_CODE = 'APP_HAS_INSTALLATIONS';
+const LIST_ENVIRONMENT_PAGE_SIZE = 25;
class MissingAppError extends cli_shared_1.UserError {
}
exports.MissingAppError = MissingAppError;
+class EnvironmentNotFoundError extends cli_shared_1.UserError {
+}
+exports.EnvironmentNotFoundError = EnvironmentNotFoundError;
class GraphqlClient {
graphqlClient;
constructor(graphqlClient) {
this.graphqlClient = graphqlClient;
@@ -47,42 +51,96 @@
statusCode: error.statusCode
});
}
}
- async listEnvironment(details) {
+ async getEnvironmentByKey(details) {
const query = `
- query forge_cli_listEnvironment($id: ID!) {
- app(id: $id) {
- environments {
+ query forge_cli_getEnvironmentByKey($appAri: ID!, $environmentKey: String!) {
+ app(id: $appAri) {
+ id
+ environmentByKey(key: $environmentKey) {
id
+ appId
key
type
- createdAt
- versions(first: 1) {
- nodes {
- updatedAt
- requiredProducts
+ }
+ }
+ }
+ `;
+ const { app } = await this.graphqlClient.query(query, {
+ appAri: details.appId,
+ environmentKey: details.environmentKey
+ });
+ if (!app) {
+ throw new MissingAppError();
+ }
+ const environment = app.environmentByKey;
+ if (!environment) {
+ throw new EnvironmentNotFoundError(`Environment '${details.environmentKey}' not found`);
+ }
+ return {
+ id: environment.id,
+ appId: environment.appId,
+ key: environment.key,
+ type: environment.type
+ };
+ }
+ async listEnvironmentPage(details, pageSize = LIST_ENVIRONMENT_PAGE_SIZE) {
+ const query = `
+ query forge_cli_listEnvironment($id: ID!, $last: Int!, $before: String) {
+ app(id: $id) {
+ environmentsPage(last: $last, before: $before) {
+ nodes {
+ id
+ key
+ type
+ createdAt
+ versions(first: 1) {
+ nodes {
+ updatedAt
+ requiredProducts
+ }
}
}
+ pageInfo {
+ hasPreviousPage
+ startCursor
+ }
+ totalCount
}
}
}
`;
const { app } = await this.graphqlClient.query(query, {
- id: details.appId
+ id: details.appId,
+ last: pageSize,
+ before: details.before
});
if (!app) {
throw new MissingAppError();
}
- return app.environments.map((environment) => {
+ const environmentsPage = app.environmentsPage;
+ if (!environmentsPage?.nodes) {
return {
- id: environment.id,
- type: environment.type,
- key: environment.key,
- lastDeployedAt: environment.versions?.nodes?.[0]?.updatedAt || environment.createdAt,
- requiredProducts: environment.versions?.nodes?.[0]?.requiredProducts || []
+ environments: [],
+ hasPreviousPage: false
};
- });
+ }
+ const environments = environmentsPage.nodes
+ .filter((env) => env !== null)
+ .map((environment) => ({
+ id: environment.id,
+ type: environment.type,
+ key: environment.key,
+ lastDeployedAt: environment.versions?.nodes?.[0]?.updatedAt || environment.createdAt,
+ requiredProducts: environment.versions?.nodes?.[0]?.requiredProducts || []
+ }));
+ return {
+ environments,
+ hasPreviousPage: environmentsPage.pageInfo?.hasPreviousPage ?? false,
+ startCursor: environmentsPage.pageInfo?.startCursor ?? undefined,
+ totalCount: environmentsPage.totalCount ?? undefined
+ };
}
async deleteEnvironments(details) {
const results = [];
for (const environmentKey of details.environmentKeys) {