feat: Implement get flow graphQL query
This commit is contained in:
29
packages/backend/src/graphql/queries/get-flow.ts
Normal file
29
packages/backend/src/graphql/queries/get-flow.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
|
import Flow from '../../models/flow';
|
||||||
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
import flowType from '../types/flow';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
|
const flowParams = { user_id: req.currentUser.id, id: params.id }
|
||||||
|
|
||||||
|
const flow = await Flow.query()
|
||||||
|
.withGraphFetched('steps')
|
||||||
|
.findOne(flowParams)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getFlow = {
|
||||||
|
type: flowType,
|
||||||
|
args: {
|
||||||
|
id: { type: GraphQLNonNull(GraphQLString) },
|
||||||
|
},
|
||||||
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getFlowResolver(params, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getFlow;
|
@@ -4,6 +4,7 @@ import getApp from './queries/get-app';
|
|||||||
import getConnectedApps from './queries/get-connected-apps';
|
import getConnectedApps from './queries/get-connected-apps';
|
||||||
import getAppConnections from './queries/get-app-connections';
|
import getAppConnections from './queries/get-app-connections';
|
||||||
import testConnection from './queries/test-connection';
|
import testConnection from './queries/test-connection';
|
||||||
|
import getFlow from './queries/get-flow';
|
||||||
import getFlows from './queries/get-flows';
|
import getFlows from './queries/get-flows';
|
||||||
|
|
||||||
const rootQuery = new GraphQLObjectType({
|
const rootQuery = new GraphQLObjectType({
|
||||||
@@ -14,6 +15,7 @@ const rootQuery = new GraphQLObjectType({
|
|||||||
getConnectedApps,
|
getConnectedApps,
|
||||||
getAppConnections,
|
getAppConnections,
|
||||||
testConnection,
|
testConnection,
|
||||||
|
getFlow,
|
||||||
getFlows
|
getFlows
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,10 +1,14 @@
|
|||||||
import { GraphQLObjectType, GraphQLString } from 'graphql';
|
import { GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql';
|
||||||
|
import StepType from './step';
|
||||||
|
|
||||||
const flowType = new GraphQLObjectType({
|
const flowType = new GraphQLObjectType({
|
||||||
name: 'Flow',
|
name: 'Flow',
|
||||||
fields: {
|
fields: {
|
||||||
id: { type: GraphQLString },
|
id: { type: GraphQLString },
|
||||||
name: { type: GraphQLString }
|
name: { type: GraphQLString },
|
||||||
|
steps: {
|
||||||
|
type: GraphQLList(StepType),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLEnumType, Grap
|
|||||||
const stepType = new GraphQLObjectType({
|
const stepType = new GraphQLObjectType({
|
||||||
name: 'Step',
|
name: 'Step',
|
||||||
fields: {
|
fields: {
|
||||||
|
id: { type: GraphQLString },
|
||||||
key: { type: GraphQLNonNull(GraphQLString) },
|
key: { type: GraphQLNonNull(GraphQLString) },
|
||||||
appKey: { type: GraphQLNonNull(GraphQLString) },
|
appKey: { type: GraphQLNonNull(GraphQLString) },
|
||||||
type: {
|
type: {
|
||||||
|
Reference in New Issue
Block a user