chore: Build graphQL query type dynamically

This commit is contained in:
Faruk AYDIN
2021-10-09 12:39:18 +02:00
committed by Ali BARIN
parent c9079db77a
commit 4dbbf37844
3 changed files with 19 additions and 12 deletions

View File

@@ -1,9 +1,21 @@
import { buildSchema } from 'graphql'; import { GraphQLObjectType, GraphQLSchema, GraphQLString, GraphQLList } from 'graphql';
import getApps from './queries/get-apps';
const graphQLSchema = buildSchema(` const queryType = new GraphQLObjectType({
type Query { name: 'Query',
getApps(name: String): [String!] fields: {
getApps: {
type: GraphQLList(GraphQLString),
args: {
name: { type: GraphQLString }
},
resolve: (_, { name }) => getApps(name)
}
} }
`); });
var graphQLSchema = new GraphQLSchema({
query: queryType,
});
export default graphQLSchema; export default graphQLSchema;

View File

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

View File

@@ -4,7 +4,6 @@ import graphQLSchema from '../graphql/graphql-schema'
const graphQLInstance = graphqlHTTP({ const graphQLInstance = graphqlHTTP({
schema: graphQLSchema, schema: graphQLSchema,
rootValue: rootResolver,
graphiql: true, graphiql: true,
}) })