feat: Implement getApp graphQL query
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { GraphQLObjectType, GraphQLSchema, GraphQLString, GraphQLList } from 'graphql';
|
import { GraphQLObjectType, GraphQLSchema, GraphQLString, GraphQLList, GraphQLNonNull } from 'graphql';
|
||||||
import getApps from './queries/get-apps';
|
import getApps from './queries/get-apps';
|
||||||
|
import getApp from './queries/get-app';
|
||||||
|
import appType from './types/app';
|
||||||
|
|
||||||
const queryType = new GraphQLObjectType({
|
const queryType = new GraphQLObjectType({
|
||||||
name: 'Query',
|
name: 'Query',
|
||||||
@@ -10,7 +12,14 @@ const queryType = new GraphQLObjectType({
|
|||||||
name: { type: GraphQLString }
|
name: { type: GraphQLString }
|
||||||
},
|
},
|
||||||
resolve: (_, { name }) => getApps(name)
|
resolve: (_, { name }) => getApps(name)
|
||||||
}
|
},
|
||||||
|
getApp: {
|
||||||
|
type: appType,
|
||||||
|
args: {
|
||||||
|
name: { type: GraphQLNonNull(GraphQLString) },
|
||||||
|
},
|
||||||
|
resolve: (_, { name }) => getApp(name)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
11
packages/backend/src/graphql/queries/get-app.ts
Normal file
11
packages/backend/src/graphql/queries/get-app.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import App from '../../models/app';
|
||||||
|
|
||||||
|
const getApp = (name: string) => {
|
||||||
|
if(!name) {
|
||||||
|
throw new Error('No name provided.')
|
||||||
|
}
|
||||||
|
|
||||||
|
return App.findOneByName(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getApp;
|
14
packages/backend/src/graphql/types/app.ts
Normal file
14
packages/backend/src/graphql/types/app.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { GraphQLObjectType, GraphQLString, GraphQLList } from 'graphql';
|
||||||
|
import fieldType from './field';
|
||||||
|
|
||||||
|
const appType = new GraphQLObjectType({
|
||||||
|
name: 'App',
|
||||||
|
fields: {
|
||||||
|
name: { type: GraphQLString },
|
||||||
|
iconUrl: { type: GraphQLString },
|
||||||
|
docUrl: { type: GraphQLString },
|
||||||
|
fields: { type: GraphQLList(fieldType) }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default appType;
|
18
packages/backend/src/graphql/types/field.ts
Normal file
18
packages/backend/src/graphql/types/field.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { GraphQLObjectType, GraphQLString, GraphQLBoolean} from 'graphql';
|
||||||
|
|
||||||
|
const fieldType = new GraphQLObjectType({
|
||||||
|
name: 'field',
|
||||||
|
fields: {
|
||||||
|
key: { type: GraphQLString },
|
||||||
|
label: { type: GraphQLString },
|
||||||
|
type: { type: GraphQLString },
|
||||||
|
required: { type: GraphQLBoolean},
|
||||||
|
readOnly: { type: GraphQLBoolean},
|
||||||
|
placeholder: { type: GraphQLString},
|
||||||
|
description: { type: GraphQLString},
|
||||||
|
docUrl: { type: GraphQLString},
|
||||||
|
clickToCopy: { type: GraphQLBoolean},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default fieldType;
|
@@ -8,6 +8,11 @@ class App {
|
|||||||
if(!name) return this.list;
|
if(!name) return this.list;
|
||||||
return this.list.filter((app) => app.includes(name.toLowerCase()));
|
return this.list.filter((app) => app.includes(name.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static findOneByName(name: string): object {
|
||||||
|
const rawAppData = fs.readFileSync(this.folderPath + `/${name}/info.json`, 'utf-8');
|
||||||
|
return JSON.parse(rawAppData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
Reference in New Issue
Block a user