refactor: Refactor queries by using related query from objectionjs
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { GraphQLList } from 'graphql';
|
||||
import Flow from '../../models/flow';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import flowType from '../types/flow';
|
||||
|
||||
const getFlowsResolver = async (req: RequestWithCurrentUser): Promise<any[]> => {
|
||||
const flows = await Flow.query()
|
||||
.withGraphJoined('[steps.[connection]]')
|
||||
.where({'flows.user_id': req.currentUser.id});
|
||||
const getFlowsResolver = async (
|
||||
req: RequestWithCurrentUser
|
||||
): Promise<any[]> => {
|
||||
const flows = await req.currentUser
|
||||
.$relatedQuery('flows')
|
||||
.withGraphJoined('[steps.[connection]]');
|
||||
|
||||
return flows;
|
||||
}
|
||||
};
|
||||
|
||||
const getFlows = {
|
||||
type: GraphQLList(flowType),
|
||||
resolve: (_: any, _params: any, req: RequestWithCurrentUser) => getFlowsResolver(req)
|
||||
}
|
||||
resolve: (_: any, _params: any, req: RequestWithCurrentUser) =>
|
||||
getFlowsResolver(req),
|
||||
};
|
||||
|
||||
export default getFlows;
|
||||
|
Reference in New Issue
Block a user