refactor: Use graphql schema directly with graphql-tools library
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
96cca96bff
commit
9926e5589e
@@ -1,29 +1,19 @@
|
||||
import { GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql';
|
||||
import appType from '../types/app';
|
||||
import App from '../../models/app';
|
||||
import { IApp } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
name: string;
|
||||
onlyWithTriggers: boolean;
|
||||
};
|
||||
|
||||
const getAppsResolver = (params: Params) => {
|
||||
const getApps = (_parent: unknown, params: Params) => {
|
||||
const apps = App.findAll(params.name);
|
||||
|
||||
if (params.onlyWithTriggers) {
|
||||
return apps.filter((app: any) => app.triggers?.length);
|
||||
return apps.filter((app: IApp) => app.triggers?.length);
|
||||
}
|
||||
|
||||
return apps;
|
||||
};
|
||||
|
||||
const getApps = {
|
||||
type: GraphQLList(appType),
|
||||
args: {
|
||||
name: { type: GraphQLString },
|
||||
onlyWithTriggers: { type: GraphQLBoolean },
|
||||
},
|
||||
resolve: (_: any, params: Params) => getAppsResolver(params),
|
||||
};
|
||||
|
||||
export default getApps;
|
||||
|
Reference in New Issue
Block a user