Skip to content

Commit

Permalink
added sorting to taskDefinitions query (#342)
Browse files Browse the repository at this point in the history
Co-authored-by: PeterL <[email protected]>
  • Loading branch information
plehocky and Skyedown authored Aug 22, 2023
1 parent 4610995 commit fd31ef3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ type Query {
filter: FilterTaskDefinitionsInput
first: Int
last: Int
orderBy: TasksOrderByInput
): TaskDefinitionConnection!
topology(filter: FilterTopologyInput): Topology
topologyCommonNodes(nodes: [String!]!): TopologyCommonNodes
Expand Down Expand Up @@ -1093,6 +1094,15 @@ enum SortPollsDirection {
desc
}

enum SortTasksBy {
name
responseTimeoutSeconds
retryCount
retryLogic
timeoutPolicy
timeoutSeconds
}

enum SortWorkflowsBy {
name
}
Expand Down Expand Up @@ -1180,6 +1190,11 @@ enum TaskTimeoutPolicy {
TIME_OUT_WF
}

input TasksOrderByInput {
direction: SortDirection!
sortKey: SortTasksBy!
}

input TerminateWorkflowInput {
reason: String
}
Expand Down
7 changes: 7 additions & 0 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ export interface NexusGenInputs {
type?: string | null; // String
workflowTaskType?: Array<NexusGenEnums['WorkflowTaskType'] | null> | null; // [WorkflowTaskType]
};
TasksOrderByInput: {
// input type
direction: NexusGenEnums['SortDirection']; // SortDirection!
sortKey: NexusGenEnums['SortTasksBy']; // SortTasksBy!
};
TerminateWorkflowInput: {
// input type
reason?: string | null; // String
Expand Down Expand Up @@ -471,6 +476,7 @@ export interface NexusGenEnums {
SortExecutedWorkflowsDirection: 'asc' | 'desc';
SortPollsBy: 'lastPollTime' | 'queueName' | 'workerId';
SortPollsDirection: 'asc' | 'desc';
SortTasksBy: 'name' | 'responseTimeoutSeconds' | 'retryCount' | 'retryLogic' | 'timeoutPolicy' | 'timeoutSeconds';
SortWorkflowsBy: 'name';
TaskTimeoutPolicy: 'ALERT_ONLY' | 'RETRY' | 'TIME_OUT_WF';
TimeoutPolicy: 'ALERT_ONLY' | 'TIME_OUT_WF';
Expand Down Expand Up @@ -2922,6 +2928,7 @@ export interface NexusGenArgTypes {
filter?: NexusGenInputs['FilterTaskDefinitionsInput'] | null; // FilterTaskDefinitionsInput
first?: number | null; // Int
last?: number | null; // Int
orderBy?: NexusGenInputs['TasksOrderByInput'] | null; // TasksOrderByInput
};
topology: {
// args
Expand Down
23 changes: 19 additions & 4 deletions src/schema/task-definitons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import config from '../config';
import { filterPollData, makeFromApiToGraphQLPollData } from '../helpers/task.helpers';
import { toGraphId } from '../helpers/id-helper';
import { getTaskDefinitionInput, getFilteredTaskDefinitions } from '../helpers/task-definition.helpers';
import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs } from './global-types';
import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs, SortDirection } from './global-types';
import { connectionFromArray } from '../helpers/connection.helpers';

const TaskTimeoutPolicy = enumType({
Expand Down Expand Up @@ -98,7 +98,17 @@ export const FilterTaskDefinitionsInput = inputObjectType({
t.string('keyword');
},
});

export const SortTasksBy = enumType({
name: 'SortTasksBy',
members: ['name', 'timeoutPolicy', 'timeoutSeconds', 'responseTimeoutSeconds', 'retryCount', 'retryLogic'],
});
export const TasksOrderByInput = inputObjectType({
name: 'TasksOrderByInput',
definition: (t) => {
t.nonNull.field('sortKey', { type: SortTasksBy });
t.nonNull.field('direction', { type: SortDirection });
},
});
export const TaskDefinitionsQuery = extendType({
type: 'Query',
definition: (t) => {
Expand All @@ -107,15 +117,20 @@ export const TaskDefinitionsQuery = extendType({
args: {
...PaginationConnectionArgs,
filter: arg({ type: FilterTaskDefinitionsInput }),
orderBy: TasksOrderByInput,
},
resolve: async (_, args, { conductorAPI }) => {
const { filter, ...paginationArgs } = args;
const { filter, orderBy: orderingArgs, ...paginationArgs } = args;
const taskDefinitions = await conductorAPI.getTaskDefinitions(config.conductorApiURL);

const filteredTaskDefs = filter?.keyword
? getFilteredTaskDefinitions(taskDefinitions, filter.keyword)
: taskDefinitions;
const orderedTaskDefs = orderingArgs?.sortKey
? orderBy(filteredTaskDefs, orderingArgs?.sortKey, orderingArgs?.direction === 'ASC' ? 'asc' : 'desc')
: filteredTaskDefs;

const tasksWithId = filteredTaskDefs.map((task) => ({
const tasksWithId = orderedTaskDefs.map((task) => ({
...task,
id: toGraphId('TaskDefinition', task.name),
}));
Expand Down

0 comments on commit fd31ef3

Please sign in to comment.