Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const {
deploymentSubscriber,
getDeploymentUrl,
getBuildLog,
getLatestDeploymentByEnvironmentId,
} = require('./resources/deployment/resolvers');

const {
Expand Down Expand Up @@ -602,6 +603,7 @@ async function getResolvers() {
pendingChanges: getPendingChangesByEnvironmentId,
apiRoutes: getRoutesByEnvironmentId,
autogeneratedRouteConfig: getAutogeneratedRouteConfigByEnvironmentId,
latestDeployment: getLatestDeploymentByEnvironmentId,
},
EnvironmentStorage: {
bytesUsed: getBytesUsed,
Expand Down
25 changes: 25 additions & 0 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ export const getDeploymentsByEnvironmentId: ResolverFn = async (
return query(sqlClientPool, queryBuilder.toString());
};

export const getLatestDeploymentByEnvironmentId: ResolverFn = async (
{ id: eid },
_args,
{ sqlClientPool, hasPermission, adminScopes }
) => {
const environment = await environmentHelpers(
sqlClientPool
).getEnvironmentById(eid);

if (!adminScopes.platformOwner && !adminScopes.platformViewer) {
await hasPermission('deployment', 'view', {
project: environment.project
});
}

const rows = await query(sqlClientPool, Sql.selectLatestDeploymentForEnvironment(environment.id));
if (rows.length === 0) {
return null;
}

const deployment = rows[0];

return deployment;
};

export const getDeploymentByRemoteId: ResolverFn = async (
_root,
{ id },
Expand Down
7 changes: 7 additions & 0 deletions services/api/src/resources/deployment/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export const Sql = {
knex('deployment')
.where('environment', '=', environment)
.toString(),
selectLatestDeploymentForEnvironment: (environment: number) =>
knex('deployment')
.where('environment', '=', environment)
.orderBy('created', 'desc')
.orderBy('id', 'desc')
.limit(1)
.toString(),
// same as select, except it deletes all deployments for the environment outside of the requested retain value
deleteDeploymentHistory: (environment: number, retain: number) =>
knex('deployment')
Expand Down
1 change: 1 addition & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ const typeDefs = gql`
The idle state of the environment
"""
idleState: IdleState
latestDeployment: Deployment
}

type EnvironmentPendingChanges {
Expand Down
Loading