From a58411ee992a8c8a22a0b9ff1ca647fbc98f3fcb Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Fri, 24 Dec 2021 20:11:19 +0300 Subject: [PATCH] chore: Expose connection with step type instead of only connectionId --- packages/backend/src/graphql/queries/get-flow.ts | 6 ++---- packages/backend/src/graphql/queries/get-flows.ts | 3 ++- packages/backend/src/graphql/types/step.ts | 3 ++- packages/backend/src/models/step.ts | 11 ++++++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/graphql/queries/get-flow.ts b/packages/backend/src/graphql/queries/get-flow.ts index bc74ebd2..752edb8e 100644 --- a/packages/backend/src/graphql/queries/get-flow.ts +++ b/packages/backend/src/graphql/queries/get-flow.ts @@ -8,11 +8,9 @@ type Params = { } 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) + .withGraphJoined('[steps.[connection]]') + .findOne({'flows.user_id': req.currentUser.id, 'flows.id': params.id}) .throwIfNotFound(); return flow; diff --git a/packages/backend/src/graphql/queries/get-flows.ts b/packages/backend/src/graphql/queries/get-flows.ts index 3e8e2437..c1437d85 100644 --- a/packages/backend/src/graphql/queries/get-flows.ts +++ b/packages/backend/src/graphql/queries/get-flows.ts @@ -5,7 +5,8 @@ import flowType from '../types/flow'; const getFlowsResolver = async (req: RequestWithCurrentUser) => { const flows = await Flow.query() - .where({ user_id: req.currentUser.id}); + .withGraphJoined('[steps.[connection]]') + .where({'flows.user_id': req.currentUser.id}); return flows; } diff --git a/packages/backend/src/graphql/types/step.ts b/packages/backend/src/graphql/types/step.ts index a80bc6fb..037dd49f 100644 --- a/packages/backend/src/graphql/types/step.ts +++ b/packages/backend/src/graphql/types/step.ts @@ -1,4 +1,5 @@ import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLEnumType, GraphQLInt } from 'graphql'; +import ConnectionType from './connection'; const stepType = new GraphQLObjectType({ name: 'Step', @@ -15,7 +16,7 @@ const stepType = new GraphQLObjectType({ } }) }, - connectionId: { type: GraphQLNonNull(GraphQLInt) } + connection: { type: ConnectionType } } }) diff --git a/packages/backend/src/models/step.ts b/packages/backend/src/models/step.ts index 617e1698..6f84400d 100644 --- a/packages/backend/src/models/step.ts +++ b/packages/backend/src/models/step.ts @@ -1,5 +1,6 @@ import Base from './base'; import Flow from './flow'; +import Connection from './connection'; enum StepEnumType { 'trigger', @@ -37,9 +38,17 @@ class Step extends Base { relation: Base.BelongsToOneRelation, modelClass: Flow, join: { - from: 'step.flow_id', + from: 'steps.flow_id', to: 'flows.id', }, + }, + connection: { + relation: Base.HasOneRelation, + modelClass: Connection, + join: { + from: 'steps.connection_id', + to: 'connections.id' + }, } }) }