feat: Implement getApp graphQL query

This commit is contained in:
Faruk AYDIN
2021-10-09 13:31:44 +02:00
committed by Ali BARIN
parent 4dbbf37844
commit f36a5cb6d8
5 changed files with 59 additions and 2 deletions

View File

@@ -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 getApp from './queries/get-app';
import appType from './types/app';
const queryType = new GraphQLObjectType({
name: 'Query',
@@ -10,7 +12,14 @@ const queryType = new GraphQLObjectType({
name: { type: GraphQLString }
},
resolve: (_, { name }) => getApps(name)
}
},
getApp: {
type: appType,
args: {
name: { type: GraphQLNonNull(GraphQLString) },
},
resolve: (_, { name }) => getApp(name)
},
}
});

View 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;

View 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;

View 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;

View File

@@ -8,6 +8,11 @@ class App {
if(!name) return this.list;
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;