chore: Use only getApps query with optional name argument

This commit is contained in:
Faruk AYDIN
2021-10-08 23:31:40 +02:00
committed by Ali BARIN
parent 0e684570f8
commit e0ab059744
5 changed files with 10 additions and 23 deletions

View File

@@ -2,8 +2,7 @@ import { buildSchema } from 'graphql';
const graphQLSchema = buildSchema(`
type Query {
getApps: [String!]
getAppsByName(name: String!): [String!]
getApps(name: String): [String!]
}
`);

View File

@@ -1,11 +0,0 @@
import App from '../../models/app';
type Params = {
name: string
}
const getAppsByName = (params: Params) => {
return App.findAllByName(params.name)
}
export default getAppsByName;

View File

@@ -1,7 +1,11 @@
import App from '../../models/app';
const getApps = () => {
return App.findAll()
type Params = {
name: string
}
const getApps = (params: Params) => {
return App.findAll(params.name)
}
export default getApps;

View File

@@ -1,9 +1,7 @@
import getApps from './queries/get-apps';
import getAppsByName from './queries/get-apps-by-name';
const rootResolver = {
getApps: getApps,
getAppsByName: getAppsByName
getApps: getApps
};
export default rootResolver;

View File

@@ -4,11 +4,8 @@ class App {
static folderPath = __dirname + '/../apps'
static list = fs.readdirSync(this.folderPath);
static findAll(): string[] {
return this.list;
}
static findAllByName(name: string): string[] {
static findAll(name?: string): string[] {
if(!name) return this.list;
return this.list.filter((app) => app.includes(name.toLowerCase()));
}
}