refactor: rewrite get app connections with RQ

This commit is contained in:
Rıdvan Akca
2024-04-05 15:44:23 +02:00
parent d74af4931e
commit d4e4d95b6d
8 changed files with 37 additions and 81 deletions

View File

@@ -1,41 +0,0 @@
import App from '../../models/app.js';
import Connection from '../../models/connection.js';
const getApp = async (_parent, params, context) => {
const conditions = context.currentUser.can('read', 'Connection');
const userConnections = context.currentUser.$relatedQuery('connections');
const allConnections = Connection.query();
const connectionBaseQuery = conditions.isCreator
? userConnections
: allConnections;
const app = await App.findOneByKey(params.key);
if (context.currentUser) {
const connections = await connectionBaseQuery
.clone()
.select('connections.*')
.withGraphFetched({
appConfig: true,
appAuthClient: true,
})
.fullOuterJoinRelated('steps')
.where({
'connections.key': params.key,
'connections.draft': false,
})
.countDistinct('steps.flow_id as flowCount')
.groupBy('connections.id')
.orderBy('created_at', 'desc');
return {
...app,
connections,
};
}
return app;
};
export default getApp;

View File

@@ -1,4 +1,3 @@
import getApp from './queries/get-app.js';
import getAppAuthClient from './queries/get-app-auth-client.ee.js';
import getBillingAndUsage from './queries/get-billing-and-usage.ee.js';
import getConnectedApps from './queries/get-connected-apps.js';
@@ -7,7 +6,6 @@ import getStepWithTestExecutions from './queries/get-step-with-test-executions.j
import testConnection from './queries/test-connection.js';
const queryResolvers = {
getApp,
getAppAuthClient,
getBillingAndUsage,
getConnectedApps,

View File

@@ -1,5 +1,4 @@
type Query {
getApp(key: String!): App
getAppAuthClient(id: String!): AppAuthClient
getConnectedApps(name: String): [App]
testConnection(id: String!): Connection