Merge pull request #393 from automatisch/issue-389

feat: add paging capability in getFlows query
This commit is contained in:
Ömer Faruk Aydın
2022-08-06 19:36:10 +03:00
committed by GitHub
2 changed files with 25 additions and 12 deletions

View File

@@ -1,22 +1,26 @@
import Context from '../../types/express/context'; import Context from '../../types/express/context';
import paginate from '../../helpers/pagination';
import Flow from '../../models/flow';
type Params = { type Params = {
appKey?: string; appKey?: string;
limit: number;
offset: number;
}; };
const getFlows = async (_parent: unknown, params: Params, context: Context) => { const getFlows = async (_parent: unknown, params: Params, context: Context) => {
const flowsQuery = context.currentUser const flowsQuery = Flow.query()
.$relatedQuery('flows') .joinRelated('steps')
.withGraphJoined('[steps.[connection]]') .withGraphFetched('steps.[connection]')
.orderBy('created_at', 'desc'); .where('flows.user_id', context.currentUser.id)
.andWhere((builder) => {
if (params.appKey) { if (params.appKey) {
flowsQuery.where('steps.app_key', params.appKey); builder.where('steps.app_key', params.appKey);
} }
})
.orderBy('updated_at', 'desc');
const flows = await flowsQuery; return paginate(flowsQuery, params.limit, params.offset);
return flows;
}; };
export default getFlows; export default getFlows;

View File

@@ -4,7 +4,7 @@ type Query {
getConnectedApps(name: String): [App] getConnectedApps(name: String): [App]
testConnection(id: String!): Connection testConnection(id: String!): Connection
getFlow(id: String!): Flow getFlow(id: String!): Flow
getFlows(appKey: String): [Flow] getFlows(limit: Int!, offset: Int!, appKey: String): FlowConnection
getStepWithTestExecutions(stepId: String!): [Step] getStepWithTestExecutions(stepId: String!): [Step]
getExecutions(limit: Int!, offset: Int!): ExecutionConnection getExecutions(limit: Int!, offset: Int!): ExecutionConnection
getExecutionSteps( getExecutionSteps(
@@ -189,6 +189,15 @@ type Field {
clickToCopy: Boolean clickToCopy: Boolean
} }
type FlowConnection {
edges: [FlowEdge]
pageInfo: PageInfo
}
type FlowEdge {
node: Flow
}
type Flow { type Flow {
id: String id: String
name: String name: String