From 7ca37c412e6304446d4d937514553f77990f13ca Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 3 Aug 2023 19:07:01 +0000 Subject: [PATCH] fix: clone base db queries --- packages/backend/src/graphql/queries/get-app.ts | 1 + packages/backend/src/graphql/queries/get-connected-apps.ts | 2 ++ packages/backend/src/graphql/queries/get-dynamic-data.ts | 1 + packages/backend/src/graphql/queries/get-dynamic-fields.ts | 1 + packages/backend/src/graphql/queries/get-execution-steps.ts | 1 + packages/backend/src/graphql/queries/get-execution.ts | 1 + packages/backend/src/graphql/queries/get-executions.ts | 1 + packages/backend/src/graphql/queries/get-flow.ts | 1 + packages/backend/src/graphql/queries/get-flows.ts | 1 + .../src/graphql/queries/get-step-with-test-executions.ts | 2 ++ packages/backend/src/graphql/queries/test-connection.ts | 1 + 11 files changed, 13 insertions(+) diff --git a/packages/backend/src/graphql/queries/get-app.ts b/packages/backend/src/graphql/queries/get-app.ts index c9ebaf52..241e8be8 100644 --- a/packages/backend/src/graphql/queries/get-app.ts +++ b/packages/backend/src/graphql/queries/get-app.ts @@ -17,6 +17,7 @@ const getApp = async (_parent: unknown, params: Params, context: Context) => { if (context.currentUser) { const connections = await connectionBaseQuery + .clone() .select('connections.*') .fullOuterJoinRelated('steps') .where({ diff --git a/packages/backend/src/graphql/queries/get-connected-apps.ts b/packages/backend/src/graphql/queries/get-connected-apps.ts index 2b328e6a..a9d740d3 100644 --- a/packages/backend/src/graphql/queries/get-connected-apps.ts +++ b/packages/backend/src/graphql/queries/get-connected-apps.ts @@ -26,12 +26,14 @@ const getConnectedApps = async ( let apps = await App.findAll(params.name); const connections = await connectionBaseQuery + .clone() .select('connections.key') .where({ draft: false }) .count('connections.id as count') .groupBy('connections.key'); const flows = await flowBaseQuery + .clone() .withGraphJoined('steps') .orderBy('created_at', 'desc'); diff --git a/packages/backend/src/graphql/queries/get-dynamic-data.ts b/packages/backend/src/graphql/queries/get-dynamic-data.ts index a5c40bb5..73b286bb 100644 --- a/packages/backend/src/graphql/queries/get-dynamic-data.ts +++ b/packages/backend/src/graphql/queries/get-dynamic-data.ts @@ -23,6 +23,7 @@ const getDynamicData = async ( const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const step = await stepBaseQuery + .clone() .withGraphFetched({ connection: true, flow: true, diff --git a/packages/backend/src/graphql/queries/get-dynamic-fields.ts b/packages/backend/src/graphql/queries/get-dynamic-fields.ts index d4529a7e..a066ab48 100644 --- a/packages/backend/src/graphql/queries/get-dynamic-fields.ts +++ b/packages/backend/src/graphql/queries/get-dynamic-fields.ts @@ -21,6 +21,7 @@ const getDynamicFields = async ( const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const step = await stepBaseQuery + .clone() .withGraphFetched({ connection: true, flow: true, diff --git a/packages/backend/src/graphql/queries/get-execution-steps.ts b/packages/backend/src/graphql/queries/get-execution-steps.ts index da941058..84c8e89c 100644 --- a/packages/backend/src/graphql/queries/get-execution-steps.ts +++ b/packages/backend/src/graphql/queries/get-execution-steps.ts @@ -19,6 +19,7 @@ const getExecutionSteps = async ( const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions; const execution = await executionBaseQuery + .clone() .withSoftDeleted() .findById(params.executionId) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/queries/get-execution.ts b/packages/backend/src/graphql/queries/get-execution.ts index 75f1440e..76dab4d7 100644 --- a/packages/backend/src/graphql/queries/get-execution.ts +++ b/packages/backend/src/graphql/queries/get-execution.ts @@ -16,6 +16,7 @@ const getExecution = async ( const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions; const execution = await executionBaseQuery + .clone() .withGraphFetched({ flow: { steps: true, diff --git a/packages/backend/src/graphql/queries/get-executions.ts b/packages/backend/src/graphql/queries/get-executions.ts index 142716f0..dec2ed38 100644 --- a/packages/backend/src/graphql/queries/get-executions.ts +++ b/packages/backend/src/graphql/queries/get-executions.ts @@ -29,6 +29,7 @@ const getExecutions = async ( `; const executions = executionBaseQuery + .clone() .joinRelated('executionSteps as execution_steps') .select('executions.*', raw(selectStatusStatement)) .withSoftDeleted() diff --git a/packages/backend/src/graphql/queries/get-flow.ts b/packages/backend/src/graphql/queries/get-flow.ts index 156eb7e2..c071ff86 100644 --- a/packages/backend/src/graphql/queries/get-flow.ts +++ b/packages/backend/src/graphql/queries/get-flow.ts @@ -12,6 +12,7 @@ const getFlow = async (_parent: unknown, params: Params, context: Context) => { const baseQuery = conditions.isCreator ? userFlows : allFlows; const flow = await baseQuery + .clone() .withGraphJoined('[steps.[connection]]') .orderBy('steps.position', 'asc') .findOne({ 'flows.id': params.id }) diff --git a/packages/backend/src/graphql/queries/get-flows.ts b/packages/backend/src/graphql/queries/get-flows.ts index 251ab9cb..fe09b310 100644 --- a/packages/backend/src/graphql/queries/get-flows.ts +++ b/packages/backend/src/graphql/queries/get-flows.ts @@ -17,6 +17,7 @@ const getFlows = async (_parent: unknown, params: Params, context: Context) => { const baseQuery = conditions.isCreator ? userFlows : allFlows; const flowsQuery = baseQuery + .clone() .joinRelated({ steps: true, }) diff --git a/packages/backend/src/graphql/queries/get-step-with-test-executions.ts b/packages/backend/src/graphql/queries/get-step-with-test-executions.ts index 051fa807..70f06455 100644 --- a/packages/backend/src/graphql/queries/get-step-with-test-executions.ts +++ b/packages/backend/src/graphql/queries/get-step-with-test-executions.ts @@ -18,10 +18,12 @@ const getStepWithTestExecutions = async ( const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const step = await stepBaseQuery + .clone() .findOne({ 'steps.id': params.stepId }) .throwIfNotFound(); const previousStepsWithCurrentStep = await stepBaseQuery + .clone() .withGraphJoined('executionSteps') .where('flow_id', '=', step.flowId) .andWhere('position', '<', step.position) diff --git a/packages/backend/src/graphql/queries/test-connection.ts b/packages/backend/src/graphql/queries/test-connection.ts index 6b785cc3..e97a51bd 100644 --- a/packages/backend/src/graphql/queries/test-connection.ts +++ b/packages/backend/src/graphql/queries/test-connection.ts @@ -19,6 +19,7 @@ const testConnection = async ( const connectionBaseQuery = conditions.isCreator ? userConnections : allConnections; let connection = await connectionBaseQuery + .clone() .findOne({ id: params.id, })