chore: Refactor graphQL queries structure

This commit is contained in:
Faruk AYDIN
2021-10-11 21:01:34 +02:00
committed by Ali BARIN
parent 1d65a7c0dd
commit 61e1488e11
6 changed files with 52 additions and 39 deletions

View File

@@ -1,11 +1,27 @@
import { GraphQLString, GraphQLNonNull } from 'graphql';
import App from '../../models/app';
import appType from '../types/app';
const getApp = (name: string) => {
if(!name) {
type Params = {
name: string
}
const getAppResolver = (params: Params) => {
if(!params.name) {
throw new Error('No name provided.')
}
return App.findOneByName(name)
return App.findOneByName(params.name)
}
const getApp = {
type: appType,
args: {
name: { type: GraphQLNonNull(GraphQLString) },
},
resolve: (_: any, params: Params) => getAppResolver(params)
}
export default getApp;