graphql-w-persistent 0.1.0.1 → 0.1.0.2
raw patch · 4 files changed
+40/−26 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- graphql-w-persistent.cabal +1/−1
- src/Components/DataProcessors/PersistentDataProcessor.hs +1/−1
- src/Components/Parsers/QueryParser.hs +35/−22
- src/GraphQL.hs +3/−2
graphql-w-persistent.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.1 +version: 0.1.0.2 -- A short (one-line) description of the package. synopsis: Haskell GraphQL query parser-interpreter-data processor.
src/Components/DataProcessors/PersistentDataProcessor.hs view
@@ -12,7 +12,7 @@ -- with root objects we want one json representation of separate graphql results... processReturnedValues :: [RootObject] -> [[[[Text]]]] -> String -processReturnedValues robjs rlts = encodeStrict $ toJSObject [("data", toJSObject [processReturnedValue x y | x<-robjs, y<-groupSingleQueryResults rlts])] +processReturnedValues robjs rlts = encodeStrict $ toJSObject [("data", toJSObject [processReturnedValue x y | (x,y)<- zip robjs $ groupSingleQueryResults rlts])] -- with separated sql query results, we want a list of data rows that are separated by only graphql query... groupSingleQueryResults :: [[[[Text]]]] -> [[[Text]]] groupSingleQueryResults rlts = [foldr (\y z -> y++z) [] x | x<-rlts]
src/Components/Parsers/QueryParser.hs view
@@ -87,7 +87,7 @@ | h=='}'&&l==1&&m==False = getQueryAndFragmentsHelper t (l-1) True (q++[h]) f | h=='}'&&m==False = getQueryAndFragmentsHelper t (l-1) m (q++[h]) f | m==False = getQueryAndFragmentsHelper t l m (q++[h]) f - | m==True = getQueryAndFragmentsHelper t l m q (f++[h]) + | otherwise = getQueryAndFragmentsHelper t l m q (f++[h]) data Fragment = Fragment { name :: String , targetObject :: ServerObject @@ -110,6 +110,7 @@ n is for name a is for arrangement o is for object + b is for -} createFragmentHelper :: String -> Int -> String -> Bool -> Bool -> Bool -> Bool -> String -> String -> [(String,[String])] -> Fragment createFragmentHelper [] l acc d n a o rst1 rst2 svrobjs = if (l==1&&d==True&&n==True&&a==True&&o==True) then Fragment { name=rst1,targetObject=(readServerObject rst2 svrobjs),replacement=acc } else E.throw ParseFragmentException @@ -212,6 +213,7 @@ input is whole query string with opening and closing brackets EFFECTS: Return value is list of desired objects with specifications passing code block to separateRootObjects() where code block is not including query opening and closing brackets +TODO: change Bool to Either with exceptions -} composeObjects :: String -> [(String,[String])] -> RootObjects composeObjects [] _ = E.throw EmptyQueryException @@ -239,7 +241,7 @@ separateRootObjectsHelper :: String -> String -> [(String,[String])] -> [RootObject] separateRootObjectsHelper [] _ _ = [] separateRootObjectsHelper (h:t) acc svrobjs - | h=='{' = ((createNestedObject (acc++[h]++(extractLevel t)) svrobjs) :: RootObject):separateRootObjectsHelper (removeLevel t) [] svrobjs + | h=='{' = (((createNestedObject (acc++[h]++(extractLevel t)) svrobjs) :: RootObject):separateRootObjectsHelper (removeLevel t) [] svrobjs) | otherwise = separateRootObjectsHelper t (acc++[h]) svrobjs -- create root object from block -- EFFECTS: passing code block to parseSubFields where block is not including root object opening and closing curly brackets. @@ -260,13 +262,17 @@ -- given object header without any braces, we want the alias if there is one. parseAlias :: String -> Alias parseAlias [] = Nothing :: Alias -parseAlias str = parseAliasHelper str "" -parseAliasHelper :: String -> String -> Alias -parseAliasHelper [] _ = Nothing :: Alias -parseAliasHelper (h:t) acc - | h=='(' = Nothing :: Alias - | h==':' = (Just $ removeSpaces acc) :: Alias - | otherwise = parseAliasHelper t (acc++[h]) +parseAlias str + | (elem ':' str)&&(elem '(' str) = parseAlias $ foldr (\x y -> if x=='(' then [] else x:y) "" str + | (elem ':' str) = Just $ removeSpaces $ foldr (\x y -> if x==':' then [] else x:y) "" str + | otherwise = Nothing :: Alias +-- parseAlias str = parseAliasHelper str "" +-- parseAliasHelper :: String -> String -> Alias +-- parseAliasHelper [] _ = Nothing :: Alias +-- parseAliasHelper (h:t) acc +-- | h=='(' = Nothing :: Alias +-- | h==':' = (Just $ removeSpaces acc) :: Alias +-- | otherwise = parseAliasHelper t (acc++[h]) parseName :: String -> Name parseName [] = "" parseName str @@ -288,7 +294,7 @@ parseSubFieldsHelper [] acc [] _ = [Left $ createScalarType acc :: Field] parseSubFieldsHelper [] acc1 acc2 _ = (Left $ createScalarType (acc2++acc1)):[] parseSubFieldsHelper (h:t) acc1 acc2 svrobjs - | h==':' = parseSubFieldsHelper (removeLeadingSpaces t) (acc2++acc1) [] svrobjs + | h==':' = parseSubFieldsHelper (removeLeadingSpaces t) (acc2++acc1++[h]) [] svrobjs | h==' '&&(length acc1)>0 = parseSubFieldsHelper t [] acc1 svrobjs | h==' ' = parseSubFieldsHelper t acc1 acc2 svrobjs | h==','&&(length acc1)>0 = (Left $ createScalarType acc1 :: Field):parseSubFieldsHelper t [] [] svrobjs @@ -297,6 +303,7 @@ | h=='('&&(length acc2)>0 = parseSubFieldsHelper (removeSubSelection t) (acc2++(getSubSelection t)) [] svrobjs | h=='{'&&(length acc1)>0 = (Right $ (createNestedObject (acc1++[h]++(extractLevel t)) svrobjs) :: Field):parseSubFieldsHelper (removeLevel t) [] [] svrobjs | h=='{'&&(length acc2)>0 = ((Right $ (createNestedObject (acc2++[h]++(extractLevel t))) svrobjs) :: Field):parseSubFieldsHelper (removeLevel t) [] [] svrobjs + | h=='}' = parseSubFieldsHelper t acc1 acc2 svrobjs | (length acc2)>0 = (Left $ createScalarType acc2 :: Field):parseSubFieldsHelper t (acc1++[h]) [] svrobjs | otherwise = parseSubFieldsHelper t (acc1++[h]) [] svrobjs removeLeadingSpaces :: String -> String @@ -310,23 +317,25 @@ getSubSelection :: String -> String getSubSelection [] = [] getSubSelection (h:t) = if h==')' then [] else h:getSubSelection t +-- pull level and leave out closing brace. extractLevel :: String -> String extractLevel [] = [] extractLevel str = extractLevelHelper str 0 extractLevelHelper :: String -> Int -> String extractLevelHelper [] _ = [] extractLevelHelper (h:t) l - | h=='{' = '{':extractLevelHelper t (l+1) + | h=='{' = h:extractLevelHelper t (l+1) | h=='}'&&l==0 = [] | h=='}' = '}':extractLevelHelper t (l-1) | otherwise = h:extractLevelHelper t l +-- remove level and leave out closing brace removeLevel :: String -> String removeLevel [] = [] removeLevel str = removeLevelHelper str 0 removeLevelHelper :: String -> Int -> String removeLevelHelper [] _ = [] removeLevelHelper (h:t) l - | l<0 = t + | l<0 = h:t | h=='{' = removeLevelHelper t (l+1) | h=='}' = removeLevelHelper t (l-1) | otherwise = removeLevelHelper t l @@ -334,15 +343,19 @@ removeSpaces str = [x | x <- str, x/=' '] createScalarType :: String -> ScalarType createScalarType [] = E.throw InvalidScalarException -createScalarType str = createScalarTypeHelper str "" "" -createScalarTypeHelper :: String -> String -> String -> ScalarType -createScalarTypeHelper [] x [] = ScalarType (Nothing :: Alias) (x :: Name) (Nothing :: Transformation) (Nothing :: Argument) -createScalarTypeHelper [] [] x = ScalarType (Nothing :: Alias) (x :: Name) (Nothing :: Transformation) (Nothing :: Argument) -createScalarTypeHelper [] x y = ScalarType (Just y :: Alias) (x :: Name) (Nothing :: Transformation) (Nothing :: Argument) -createScalarTypeHelper (h:t) acc1 acc2 - | h==':' = createScalarTypeHelper t [] acc1 - | h=='(' = ScalarType (Just acc2 :: Alias) (acc1 :: Name) ((Just $ foldr (\x y -> if x==':' then [] else x:y) [] t) :: Transformation) ((Just $ foldl (\y x -> if x==':' then [] else (y++[x])) [] (foldr (\x y -> if x==')' then [] else x:y) [] t)) :: Argument) - | otherwise = createScalarTypeHelper t (acc1++[h]) acc2 +createScalarType str = ScalarType (parseAlias str :: Alias) (parseName str :: Name) (parseTransformation str :: Transformation) (parseArgument str :: Argument) +parseTransformation :: String -> Transformation +parseTransformation [] = Nothing :: Transformation +parseTransformation str + | (elem '(' str)&&(elem ':' str) = (Just $ removeSpaces $ foldr (\x y -> if x==':' then [] else x:y) "" $ foldl (\y x -> if x=='(' then [] else y++[x]) "" str) :: Transformation + | (elem '(' str) = E.throw SyntaxException + | otherwise = Nothing :: Transformation +parseArgument :: String -> Argument +parseArgument [] = Nothing :: Argument +parseArgument str + | (elem ')' str)&&(elem ':' str) = (Just $ removeSpaces $ foldr (\x y -> if x==')' then [] else x:y) "" $ foldl (\y x -> if x==':' then [] else y++[x]) "" str) :: Argument + | (elem ')' str) = E.throw SyntaxException + | otherwise = Nothing :: Argument -- parseOperation :: String -> Operation -- TODO: support mutations @@ -354,4 +367,4 @@ -- done by SQLQueryComposer.hs for sql queries {-----Step 6. PROCESS RESULTS-----} --- done by DataProcessor.hs +-- done by PersistentDataProcessor.hs
src/GraphQL.hs view
@@ -27,10 +27,10 @@ -} module GraphQL ( -- * Functions - -- This is the available methods which are giving access to the package interpretation, validation, and formatting features. + -- *** This is the available methods which are giving access to the package interpretation, validation, and formatting features. module GraphQL, -- * Server data types - -- These are server data types that are return from processQueryString. You do not need to know these to know how is this package used, but you'll get some insight to what is used to store and map your GraphQL data. + -- *** These are server data types that are return from processQueryString. You do not need to know these to know how is this package used, but you'll get some insight to what is used to store and map your GraphQL data. module Model.ServerObjectTypes ) where @@ -40,6 +40,7 @@ import Model.ServerObjectTypes import GraphQLHelper +-- * {- | This is the function to call to get queries from a GraphQL query.