Commit b04dc242 authored by Iustin Pop's avatar Iustin Pop
Browse files

Simplify a bit queryFields



We don't add a type class for fully-generic handling, but we do
abstract the duplicate part.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 90d033ef
......@@ -191,21 +191,21 @@ queryInner cfg _ (Query QRGroup fields qfilter) wanted = return $ do
queryInner _ _ (Query qkind _ _) _ =
return . Bad $ "Query '" ++ show qkind ++ "' not supported"
-- | Helper for 'queryFields'.
fieldsExtractor :: FieldMap a b -> [FilterField] -> QueryFieldsResult
fieldsExtractor fieldsMap fields =
let selected = if null fields
then map snd $ Map.toAscList fieldsMap
else getSelectedFields fieldsMap fields
in QueryFieldsResult (map fst selected)
-- | Query fields call.
-- FIXME: Looks generic enough to use a typeclass
queryFields :: QueryFields -> Result QueryFieldsResult
queryFields (QueryFields QRNode fields) =
let selected = if null fields
then map snd $ Map.toAscList nodeFieldsMap
else getSelectedFields nodeFieldsMap fields
in Ok $ QueryFieldsResult (map fst selected)
Ok $ fieldsExtractor nodeFieldsMap fields
queryFields (QueryFields QRGroup fields) =
let selected = if null fields
then map snd $ Map.toAscList groupFieldsMap
else getSelectedFields groupFieldsMap fields
in Ok $ QueryFieldsResult (map fst selected)
Ok $ fieldsExtractor groupFieldsMap fields
queryFields (QueryFields qkind _) =
Bad $ "QueryFields '" ++ show qkind ++ "' not supported"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment