refactor: Use graphql schema directly with graphql-tools library

This commit is contained in:
Faruk AYDIN
2022-03-06 18:16:28 +03:00
committed by Ömer Faruk Aydın
parent 96cca96bff
commit 9926e5589e
48 changed files with 551 additions and 839 deletions

View File

@@ -1,22 +1,22 @@
import { GraphQLList, GraphQLNonNull } from 'graphql';
import App from '../../models/app';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import connectionType from '../types/connection';
import availableAppsEnumType from '../types/available-apps-enum-type';
import Context from '../../types/express/context';
type Params = {
key: string;
};
const getAppConnectionsResolver = async (
const getAppConnections = async (
_parent: unknown,
params: Params,
req: RequestWithCurrentUser
context: Context
) => {
const app = App.findOneByKey(params.key);
const connections = await req.currentUser.$relatedQuery('connections').where({
key: params.key,
});
const connections = await context.currentUser
.$relatedQuery('connections')
.where({
key: params.key,
});
return connections.map((connection) => ({
...connection,
@@ -24,13 +24,4 @@ const getAppConnectionsResolver = async (
}));
};
const getAppConnections = {
type: GraphQLList(connectionType),
args: {
key: { type: GraphQLNonNull(availableAppsEnumType) },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
getAppConnectionsResolver(params, req),
};
export default getAppConnections;