chore: Build graphQL query type dynamically
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import { buildSchema } from 'graphql';
|
||||
import { GraphQLObjectType, GraphQLSchema, GraphQLString, GraphQLList } from 'graphql';
|
||||
import getApps from './queries/get-apps';
|
||||
|
||||
const graphQLSchema = buildSchema(`
|
||||
type Query {
|
||||
getApps(name: String): [String!]
|
||||
const queryType = new GraphQLObjectType({
|
||||
name: 'Query',
|
||||
fields: {
|
||||
getApps: {
|
||||
type: GraphQLList(GraphQLString),
|
||||
args: {
|
||||
name: { type: GraphQLString }
|
||||
},
|
||||
resolve: (_, { name }) => getApps(name)
|
||||
}
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
var graphQLSchema = new GraphQLSchema({
|
||||
query: queryType,
|
||||
});
|
||||
|
||||
export default graphQLSchema;
|
||||
|
@@ -1,11 +1,7 @@
|
||||
import App from '../../models/app';
|
||||
|
||||
type Params = {
|
||||
name: string
|
||||
}
|
||||
|
||||
const getApps = (params: Params) => {
|
||||
return App.findAll(params.name)
|
||||
const getApps = (name: string) => {
|
||||
return App.findAll(name)
|
||||
}
|
||||
|
||||
export default getApps;
|
||||
|
@@ -4,7 +4,6 @@ import graphQLSchema from '../graphql/graphql-schema'
|
||||
|
||||
const graphQLInstance = graphqlHTTP({
|
||||
schema: graphQLSchema,
|
||||
rootValue: rootResolver,
|
||||
graphiql: true,
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user