diff --git a/src/schema/api.graphql b/src/schema/api.graphql index 6b24adda..fe46436b 100644 --- a/src/schema/api.graphql +++ b/src/schema/api.graphql @@ -940,7 +940,14 @@ type Query { uniconfigShellSession: String workflowInstanceDetail(shouldIncludeTasks: Boolean, workflowId: String!): WorkflowInstanceDetail workflowLabels: [String!]! - workflows(after: String, before: String, filter: FilterWorkflowsInput, first: Int, last: Int): WorkflowConnection! + workflows( + after: String + before: String + filter: FilterWorkflowsInput + first: Int + last: Int + orderBy: WorkflowsOrderByInput! + ): WorkflowConnection! zones(after: String, before: String, first: Int, last: Int): ZonesConnection! } @@ -1072,6 +1079,10 @@ enum SortPollsDirection { desc } +enum SortWorkflowsBy { + name +} + input StartWorkflowRequestInput { workflow: ExecuteNewWorkflowInput! workflowDefinition: WorkflowDefinitionInput @@ -1360,6 +1371,11 @@ enum WorkflowTaskType { WAIT } +input WorkflowsOrderByInput { + direction: SortDirection! + sortKey: SortWorkflowsBy! +} + type Zone implements Node { createdAt: String! id: ID! diff --git a/src/schema/device.ts b/src/schema/device.ts index 62a5d328..525ef660 100644 --- a/src/schema/device.ts +++ b/src/schema/device.ts @@ -30,7 +30,7 @@ import { CSVParserToPromise, CSVValuesToJSON, isHeaderValid } from '../helpers/i import { getUniconfigURL } from '../helpers/zone.helpers'; import { sshClient } from '../uniconfig-shell'; import { Blueprint } from './blueprint'; -import { Node, PageInfo, PaginationConnectionArgs } from './global-types'; +import { Node, PageInfo, PaginationConnectionArgs, SortDirection } from './global-types'; import { LabelConnection } from './label'; import { Location } from './location'; import { Zone } from './zone'; @@ -177,10 +177,6 @@ export const SortDeviceBy = enumType({ name: 'SortDeviceBy', members: ['NAME', 'CREATED_AT'], }); -export const SortDirection = enumType({ - name: 'SortDirection', - members: ['ASC', 'DESC'], -}); export const DeviceOrderByInput = inputObjectType({ name: 'DeviceOrderByInput', definition: (t) => { diff --git a/src/schema/global-types.ts b/src/schema/global-types.ts index c77ea728..a63b30e2 100644 --- a/src/schema/global-types.ts +++ b/src/schema/global-types.ts @@ -1,5 +1,5 @@ import countries from 'i18n-iso-countries'; -import { extendType, idArg, intArg, interfaceType, nonNull, objectType, stringArg } from 'nexus'; +import { enumType, extendType, idArg, intArg, interfaceType, nonNull, objectType, stringArg } from 'nexus'; import config from '../config'; import conductorAPI from '../external-api/conductor'; import { fromGraphId, getType } from '../helpers/id-helper'; @@ -180,3 +180,8 @@ export const IsOkResponse = objectType({ t.nonNull.boolean('isOk'); }, }); + +export const SortDirection = enumType({ + name: 'SortDirection', + members: ['ASC', 'DESC'], +}); diff --git a/src/schema/nexus-typegen.ts b/src/schema/nexus-typegen.ts index 0f9693c0..8790b258 100644 --- a/src/schema/nexus-typegen.ts +++ b/src/schema/nexus-typegen.ts @@ -432,6 +432,11 @@ export interface NexusGenInputs { updatedAt?: string | null; // String version?: number | null; // Int }; + WorkflowsOrderByInput: { + // input type + direction: NexusGenEnums['SortDirection']; // SortDirection! + sortKey: NexusGenEnums['SortWorkflowsBy']; // SortWorkflowsBy! + }; } export interface NexusGenEnums { @@ -460,6 +465,7 @@ export interface NexusGenEnums { SortExecutedWorkflowsDirection: 'asc' | 'desc'; SortPollsBy: 'lastPollTime' | 'queueName' | 'workerId'; SortPollsDirection: 'asc' | 'desc'; + SortWorkflowsBy: 'name'; TaskTimeoutPolicy: 'ALERT_ONLY' | 'RETRY' | 'TIME_OUT_WF'; TimeoutPolicy: 'ALERT_ONLY' | 'TIME_OUT_WF'; WorkflowTaskType: @@ -2931,6 +2937,7 @@ export interface NexusGenArgTypes { filter?: NexusGenInputs['FilterWorkflowsInput'] | null; // FilterWorkflowsInput first?: number | null; // Int last?: number | null; // Int + orderBy: NexusGenInputs['WorkflowsOrderByInput']; // WorkflowsOrderByInput! }; zones: { // args diff --git a/src/schema/workflow.ts b/src/schema/workflow.ts index e3e839a5..f25cb5c4 100644 --- a/src/schema/workflow.ts +++ b/src/schema/workflow.ts @@ -18,7 +18,7 @@ import config from '../config'; import { WorkflowDetailInput } from '../external-api/conductor-network-types'; import { fromGraphId, toGraphId } from '../helpers/id-helper'; import getLogger from '../get-logger'; -import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs } from './global-types'; +import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs, SortDirection } from './global-types'; import { TaskInput, ExecutedWorkflowTask } from './task'; import { convertToApiOutputParameters, @@ -146,6 +146,19 @@ export const FilterWorkflowsInput = inputObjectType({ }, }); +export const SortWorkflowsBy = enumType({ + name: 'SortWorkflowsBy', + members: ['name'], +}); + +export const WorkflowsOrderByInput = inputObjectType({ + name: 'WorkflowsOrderByInput', + definition: (t) => { + t.nonNull.field('sortKey', { type: SortWorkflowsBy }); + t.nonNull.field('direction', { type: SortDirection }); + }, +}); + export const WorkflowsQuery = extendType({ type: 'Query', definition: (t) => { @@ -154,15 +167,22 @@ export const WorkflowsQuery = extendType({ args: { ...PaginationConnectionArgs, filter: FilterWorkflowsInput, + orderBy: nonNull(WorkflowsOrderByInput), }, resolve: async (_, args, { conductorAPI }) => { - const { filter, ...paginationArgs } = args; + const { filter, orderBy: orderingArgs, ...paginationArgs } = args; const workflows = await conductorAPI.getWorkflowMetadata(config.conductorApiURL); const filteredWorkflows = filter?.labels || filter?.keyword ? getFilteredWorkflows(workflows, filter) : workflows; - const workflowsWithId = filteredWorkflows.map((w) => ({ + const orderedData = orderBy( + filteredWorkflows, + [orderingArgs.sortKey], + [orderingArgs.direction === 'ASC' ? 'asc' : 'desc'], + ); + + const workflowsWithId = orderedData.map((w) => ({ ...w, id: w.name, }));