chore: Use only getApps query with optional name argument
This commit is contained in:
@@ -2,8 +2,7 @@ import { buildSchema } from 'graphql';
|
|||||||
|
|
||||||
const graphQLSchema = buildSchema(`
|
const graphQLSchema = buildSchema(`
|
||||||
type Query {
|
type Query {
|
||||||
getApps: [String!]
|
getApps(name: String): [String!]
|
||||||
getAppsByName(name: String!): [String!]
|
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@@ -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;
|
|
@@ -1,7 +1,11 @@
|
|||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
|
|
||||||
const getApps = () => {
|
type Params = {
|
||||||
return App.findAll()
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const getApps = (params: Params) => {
|
||||||
|
return App.findAll(params.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getApps;
|
export default getApps;
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
import getApps from './queries/get-apps';
|
import getApps from './queries/get-apps';
|
||||||
import getAppsByName from './queries/get-apps-by-name';
|
|
||||||
|
|
||||||
const rootResolver = {
|
const rootResolver = {
|
||||||
getApps: getApps,
|
getApps: getApps
|
||||||
getAppsByName: getAppsByName
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default rootResolver;
|
export default rootResolver;
|
||||||
|
@@ -4,11 +4,8 @@ class App {
|
|||||||
static folderPath = __dirname + '/../apps'
|
static folderPath = __dirname + '/../apps'
|
||||||
static list = fs.readdirSync(this.folderPath);
|
static list = fs.readdirSync(this.folderPath);
|
||||||
|
|
||||||
static findAll(): string[] {
|
static findAll(name?: string): string[] {
|
||||||
return this.list;
|
if(!name) return this.list;
|
||||||
}
|
|
||||||
|
|
||||||
static findAllByName(name: string): string[] {
|
|
||||||
return this.list.filter((app) => app.includes(name.toLowerCase()));
|
return this.list.filter((app) => app.includes(name.toLowerCase()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user