summaryrefslogtreecommitdiff
path: root/src/GraphQLHelper.hs
blob: 1596ac41819158397d7343127d8f9fb1515acc05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module GraphQLHelper where

import qualified Control.Exception as E
import qualified Components.Parsers.QueryParser as QP
import qualified Components.ObjectHandlers.ServerObjectValidator as SOV
import qualified Components.QueryComposers.SQLQueryComposer as QC
import qualified Components.ObjectHandlers.ServerObjectTrimmer as SOT
import Model.ServerObjectTypes
import Model.ServerExceptions


checkStringToObjects :: [(String,[String])] -> String -> [RootObject]
checkStringToObjects svrobjs str = if (QP.validateQuery str)==True then (QP.parseStringToObjects str svrobjs) else E.throw SyntaxException
checkObjectsToSql :: [(String,[(String,String)])] -> [(String,[String])] -> [(String,[String])] -> [(String,String,[String])] -> [RootObject] -> ([RootObject],[[String]])
checkObjectsToSql sss sos sodn sor ros = if (SOV.checkObjectsAttributes reducedRobjs sss sos)==True then (reducedRobjs,QC.makeSqlQueries reducedRobjs sodn sor) else (E.throw InvalidObjectException)
                                         where reducedRobjs = SOT.mergeDuplicatedRootObjects ros
checkObjectsToSqlWithVariables :: [(String,[(String,String)])] -> [(String,[String])] -> [(String,[String])] -> [(String,String,[String])] -> [(String,String,String)] -> [RootObject] -> ([RootObject],[[String]])
checkObjectsToSqlWithVariables sss sos sodn sor vars ros = if (SOV.checkObjectsAttributes valueObjects sss sos)==True then (valueObjects,QC.makeSqlQueries valueObjects sodn sor) else (E.throw InvalidObjectSubFieldException)
                                    where
                                        reducedObjects = SOT.mergeDuplicatedRootObjects ros
                                        valueObjects = SOV.replaceObjectsVariables sss reducedObjects vars