[graphql] implement new type errors

parent dc6f6f13
...@@ -2,18 +2,19 @@ module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where ...@@ -2,18 +2,19 @@ module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array (filter, null, (:)) import Data.Array (cons, filter, null, (:))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Effect.Aff (runAff_) import Effect.Aff (runAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam) import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam)
import Gargantext.Components.GraphQL.Team (Team, TeamMember) import Gargantext.Components.GraphQL.Team (Team, TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError, FrontendError(EC_403__user_not_authorized)) import Gargantext.Config.REST (AffRESTError, logRESTError, FrontendError(EC_403__user_not_authorized))
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (ID, NodeType) import Gargantext.Types (ID, FrontendError(FRESTError), NodeType)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -23,18 +24,18 @@ here :: R2.Here ...@@ -23,18 +24,18 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam" here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam"
type ActionManageTeam = ( type ActionManageTeam = (
id :: ID boxes :: Boxes
, nodeType :: NodeType , id :: ID
, session :: Session , nodeType :: NodeType
, session :: Session
) )
actionManageTeam :: R2.Component ActionManageTeam actionManageTeam :: R2.Component ActionManageTeam
actionManageTeam = R.createElement actionManageTeamCpt actionManageTeam = R.createElement actionManageTeamCpt
actionManageTeamCpt :: R.Component ActionManageTeam actionManageTeamCpt :: R.Component ActionManageTeam
actionManageTeamCpt = here.component "actionManageTeam" cpt where actionManageTeamCpt = here.component "actionManageTeam" cpt where
cpt {id, session} _ = do cpt { boxes: { errors }, id, session } _ = do
useLoader { errorHandler useLoader { errorHandler: errorHandler errors
, loader: loadTeam , loader: loadTeam
, path: { nodeId: id, session } , path: { nodeId: id, session }
, render: \team -> teamLayoutWrapper { team , render: \team -> teamLayoutWrapper { team
...@@ -43,7 +44,11 @@ actionManageTeamCpt = here.component "actionManageTeam" cpt where ...@@ -43,7 +44,11 @@ actionManageTeamCpt = here.component "actionManageTeam" cpt where
} [] } []
} }
where where
errorHandler = logRESTError here "teamLayout" errorHandler errors error = do
logRESTError here "teamLayout" error
T.modify_ (cons $ FRESTError { error }) errors
-- T.write_ (Just $ show error) errorS
type TeamProps = type TeamProps =
( nodeId :: ID ( nodeId :: ID
...@@ -55,17 +60,17 @@ teamLayoutWrapper :: R2.Component TeamProps ...@@ -55,17 +60,17 @@ teamLayoutWrapper :: R2.Component TeamProps
teamLayoutWrapper = R.createElement teamLayoutWrapperCpt teamLayoutWrapper = R.createElement teamLayoutWrapperCpt
teamLayoutWrapperCpt :: R.Component TeamProps teamLayoutWrapperCpt :: R.Component TeamProps
teamLayoutWrapperCpt = here.component "teamLayoutWrapper" cpt where teamLayoutWrapperCpt = here.component "teamLayoutWrapper" cpt where
cpt {nodeId, session, team: {team_owner_username, team_members}} _ = do cpt { nodeId, session, team: { team_owner_username, team_members } } _ = do
team_members <- T.useBox team_members
error <- T.useBox Nothing error <- T.useBox Nothing
team_members <- T.useBox team_members
pure $ teamLayoutRows {nodeId, session, team_members, error, team_owner_username} pure $ teamLayoutRows {nodeId, session, team_members, error, team_owner_username}
type TeamRowProps = type TeamRowProps =
( nodeId :: ID ( error :: T.Box (Maybe String)
, nodeId :: ID
, session :: Session , session :: Session
, team_members :: T.Box (Array TeamMember) , team_members :: T.Box (Array TeamMember)
, error :: T.Box (Maybe String)
, team_owner_username :: String , team_owner_username :: String
) )
......
...@@ -346,8 +346,8 @@ panelActionCpt = here.component "panelAction" cpt ...@@ -346,8 +346,8 @@ panelActionCpt = here.component "panelAction" cpt
pure $ actionDownload { id, nodeType, session } [] pure $ actionDownload { id, nodeType, session } []
cpt { action: Link {subTreeParams}, boxes, dispatch, id, nodeType, session } _ = cpt { action: Link {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ linkNode { boxes, dispatch, id, nodeType, session, subTreeParams } [] pure $ linkNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
cpt { action: ManageTeam, nodeType, id, session} _ = cpt { action: ManageTeam, boxes, nodeType, id, session} _ =
pure $ actionManageTeam { id, nodeType, session } [] pure $ actionManageTeam { boxes, id, nodeType, session } []
cpt { action: Merge {subTreeParams}, boxes, dispatch, id, nodeType, session } _ = cpt { action: Merge {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ mergeNode { boxes, dispatch, id, nodeType, session, subTreeParams } [] pure $ mergeNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
cpt { action: Move {subTreeParams}, boxes, dispatch, id, nodeType, session } _ = cpt { action: Move {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
......
...@@ -6,12 +6,15 @@ import Affjax.RequestHeader as ARH ...@@ -6,12 +6,15 @@ import Affjax.RequestHeader as ARH
import Control.Monad.Error.Class as Errors import Control.Monad.Error.Class as Errors
import Data.Argonaut.Core as AC import Data.Argonaut.Core as AC
import Data.Argonaut.Decode (JsonDecodeError) import Data.Argonaut.Decode (JsonDecodeError)
import Data.Array as A
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.List.Types (NonEmptyList) import Data.List.Types (NonEmptyList)
import Data.Maybe (Maybe(..))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, throwError, error) import Effect.Aff (Aff, throwError, error)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import FFI.Simple ((.?))
import Foreign as Foreign import Foreign as Foreign
import Gargantext.Components.GraphQL.Contact (AnnuaireContact) import Gargantext.Components.GraphQL.Contact (AnnuaireContact)
import Gargantext.Components.GraphQL.Context as GQLCTX import Gargantext.Components.GraphQL.Context as GQLCTX
...@@ -28,7 +31,7 @@ import Gargantext.Sessions (Session(..)) ...@@ -28,7 +31,7 @@ import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (type (==>)) import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient) import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
import GraphQL.Client.Query (queryFullRes, queryWithDecoder, decodeGqlRes, queryFullRes) import GraphQL.Client.Query (queryFullRes, queryWithDecoder, decodeGqlRes, getFullRes, queryFullRes)
import GraphQL.Client.SafeQueryName (safeQueryName) import GraphQL.Client.SafeQueryName (safeQueryName)
import GraphQL.Client.ToGqlString (toGqlQueryString) import GraphQL.Client.ToGqlString (toGqlQueryString)
import GraphQL.Client.Types (class GqlQuery, GqlRes, Client(..), class QueryClient, clientQuery, defQueryOpts) import GraphQL.Client.Types (class GqlQuery, GqlRes, Client(..), class QueryClient, clientQuery, defQueryOpts)
...@@ -58,56 +61,34 @@ gqlQuery :: ...@@ -58,56 +61,34 @@ gqlQuery ::
(Client client schema a b) -> (Client client schema a b) ->
String -> String ->
query -> query ->
Aff returns REST.AffRESTError returns
-- REST.AffRESTError returns
-- TODO Send this by hand, parse errors if any
-- GQL API returns status != 200 for errors.
-- gqlQuery = queryWithDecoder (Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError)
gqlQuery c@(Client client) queryNameUnsafe q = do gqlQuery c@(Client client) queryNameUnsafe q = do
-- res@{ data_ } <-
-- queryFullRes (Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError) (const $ defQueryOpts client) c queryNameUnsafe q :: Aff (GqlRes returns)
-- liftEffect $ here.log2 "[gqlQuery] res" res
-- case data_ of
-- Left err -> do
-- liftEffect $ here.log2 "[gqlQuery] err" err
-- throwError $ error "Error!"
-- Right res -> pure res
let opts = defQueryOpts client let opts = defQueryOpts client
decodeFn = Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError
handleError err = do
liftEffect $ here.log2 "[gqlQuery] error" err
pure $ AC.fromString ""
liftEffect $ here.log2 "[gqlQuery] calling query" q
json <- Errors.catchError (clientQuery opts client queryName (getVarsTypeNames q <> toGqlQueryString q) (getVarsJson q)) handleError
-- json <- clientQuery opts client queryName (getVarsTypeNames q <> toGqlQueryString q) (getVarsJson q)
-- NOTE 'json' contains interesting data, in particular the gql operation, error, etc
liftEffect $ here.log2 "[gqlQuery] json" json
-- pure $ REST.readJSON json
-- pure $ decodeJSONOrError $ Foreign.unsafeToForeign json
-- pure $ lmap foreignToRESTError $ JSON.read $ Foreign.unsafeToForeign json
-- case (JSON.read $ Foreign.unsafeToForeign json) of json <- clientQuery opts client queryName (getVarsTypeNames q <> toGqlQueryString q) (getVarsJson q)
-- Right a -> pure a
-- Left err -> throwError $ error $ show err
-- what 'decodeGqlRes' does is take 'json.data' and decode it using our custom decode function pure $ parseGQLJson json
case (decodeGqlRes decodeFn json) of
Left err -> throwError $ error $ show err
Right a -> pure a
where where
queryName = safeQueryName queryNameUnsafe queryName = safeQueryName queryNameUnsafe
parseGQLJson json =
-- decodeJSONOrError :: forall a. JSON.ReadForeign a => Foreign.Foreign -> Either RESTError a -- NOTE 'json' contains interesting data, in particular the gql operation, error, etc
-- decodeJSONOrError f = case json .? "error" of
-- lmap parseJSONError (JSON.read f :: JSON.E a) -- what 'decodeGqlRes' does is take 'json.data' and decode it using our custom decode function
-- where Nothing -> lmap (REST.ReadJSONError <<< unsafeCoerce) (decodeGqlRes decodeFn json)
-- parseJSONError :: Foreign.Foreign -> RESTError Just err ->
-- parseJSONError f = -- Surely, an error must be returned, but which one?
-- case (JSON.read f :: JSON.E FrontendError) of Left $ case err .? "graphQLErrors" of
-- Right err -> FE err Nothing -> REST.CustomError "[gqlQuery] no 'graphQLErrors'"
-- Left Just gqlErrors -> case A.head gqlErrors of
Nothing -> REST.CustomError "[gqlQuery] empty 'graphQLErrors'"
Just gqlErr -> case gqlErr .? "extensions" of
Nothing -> REST.CustomError "[gqlQuery] graphQLError no 'extensions'"
Just ext -> case (Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError $ ext) of
Left err' -> REST.CustomError $ "[gqlQuery] error reading 'extensions': " <> show err'
Right err' -> REST.FE err'
where
decodeFn = Foreign.unsafeToForeign >>> JSON.read >>> lmap toJsonError
toJsonError :: Foreign.MultipleErrors -> JsonDecodeError toJsonError :: Foreign.MultipleErrors -> JsonDecodeError
toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish
...@@ -125,7 +106,7 @@ queryGql :: ...@@ -125,7 +106,7 @@ queryGql ::
Session Session
-> String -> String
-> query -> query
-> Aff returns -> REST.AffRESTError returns
queryGql session name q = do queryGql session name q = do
--query client name q --query client name q
client <- liftEffect $ getClient session client <- liftEffect $ getClient session
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.GraphQL.Endpoints where ...@@ -3,6 +3,7 @@ module Gargantext.Components.GraphQL.Endpoints where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array as A import Data.Array as A
import Data.Bifunctor (rmap)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Map as Map import Data.Map as Map
...@@ -33,15 +34,17 @@ here = R2.here "Gargantext.Components.GraphQL.Endpoints" ...@@ -33,15 +34,17 @@ here = R2.here "Gargantext.Components.GraphQL.Endpoints"
getIMTSchools :: Session -> AffRESTError (Array GQLIMT.School) getIMTSchools :: Session -> AffRESTError (Array GQLIMT.School)
getIMTSchools session = do getIMTSchools session = do
{ imt_schools } <- queryGql session "get imt schools" $ eRes <- queryGql session "get imt schools" $ GQLIMT.schoolsQuery
GQLIMT.schoolsQuery pure $ rmap _.imt_schools eRes
liftEffect $ here.log2 "[getIMTSchools] imt_schools" imt_schools -- liftEffect $ here.log2 "[getIMTSchools] imt_schools" imt_schools
pure $ Right imt_schools -- pure $ Right imt_schools
getNode :: Session -> Int -> AffRESTError Node getNode :: Session -> Int -> AffRESTError Node
getNode session nodeId = do getNode session nodeId = do
{ nodes } <- queryGql session "get nodes" $ eRes <- queryGql session "get nodes" $ nodesQuery `withVars` { id: nodeId }
nodesQuery `withVars` { id: nodeId } case eRes of
Left err -> pure $ Left err
Right { nodes } -> do
liftEffect $ here.log2 "[getNode] node" nodes liftEffect $ here.log2 "[getNode] node" nodes
pure $ case A.head nodes of pure $ case A.head nodes of
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found") Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
...@@ -49,24 +52,31 @@ getNode session nodeId = do ...@@ -49,24 +52,31 @@ getNode session nodeId = do
getNodeCorpus :: Session -> Int -> AffRESTError Corpus getNodeCorpus :: Session -> Int -> AffRESTError Corpus
getNodeCorpus session corpusId = do getNodeCorpus session corpusId = do
{ nodes_corpus } <- queryGql session "get nodes corpus" $ eRes <- queryGql session "get nodes corpus" $
nodesCorpusQuery `withVars` { id: corpusId } nodesCorpusQuery `withVars` { id: corpusId }
case eRes of
Left err -> pure $ Left err
Right { nodes_corpus } -> do
liftEffect $ here.log2 "[getNodesCorpus] nodes_corpus" nodes_corpus liftEffect $ here.log2 "[getNodesCorpus] nodes_corpus" nodes_corpus
pure $ case A.head nodes_corpus of pure $ case A.head nodes_corpus of
Nothing -> Left (CustomError $ "corpus with id" <> show corpusId <>" not found") Nothing -> Left (CustomError $ "corpus with id" <> show corpusId <>" not found")
Just corpus -> Right corpus Just corpus -> Right corpus
getNodeParent :: Session -> Int -> NodeType -> Aff (Array Node) getNodeParent :: Session -> Int -> NodeType -> AffRESTError (Array Node)
getNodeParent session nodeId parentType = do getNodeParent session nodeId parentType = do
{ node_parent } <- queryGql session "get node parent" $ eRes <- queryGql session "get node parent" $
nodeParentQuery `withVars` { id: nodeId nodeParentQuery `withVars` { id: nodeId
, parent_type: show parentType } -- TODO: remove "show" , parent_type: show parentType } -- TODO: remove "show"
liftEffect $ here.log2 "[getNodeParent] node_parent" node_parent -- liftEffect $ here.log2 "[getNodeParent] node_parent" node_parent
pure node_parent --pure node_parent
pure $ rmap _.node_parent eRes
getUser :: Session -> Int -> AffRESTError User getUser :: Session -> Int -> AffRESTError User
getUser session id = do getUser session id = do
{ users } <- queryGql session "get user" $ userQuery `withVars` { id } eRes <- queryGql session "get user" $ userQuery `withVars` { id }
case eRes of
Left err -> pure $ Left err
Right { users } -> do
liftEffect $ here.log2 "[getUser] users" users liftEffect $ here.log2 "[getUser] users" users
pure $ case A.head users of pure $ case A.head users of
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found") Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
...@@ -104,7 +114,10 @@ updateUserEPOAPIToken session user_id api_token = do ...@@ -104,7 +114,10 @@ updateUserEPOAPIToken session user_id api_token = do
getUserInfo :: Session -> Int -> AffRESTError UserInfo getUserInfo :: Session -> Int -> AffRESTError UserInfo
getUserInfo session id = do getUserInfo session id = do
{ user_infos } <- queryGql session "get user infos" $ userInfoQuery `withVars` { id } eRes <- queryGql session "get user infos" $ userInfoQuery `withVars` { id }
case eRes of
Left err -> pure $ Left err
Right { user_infos } -> do
liftEffect $ here.log2 "[getUserInfo] user infos" user_infos liftEffect $ here.log2 "[getUserInfo] user infos" user_infos
pure $ case A.head user_infos of pure $ case A.head user_infos of
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found") Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
...@@ -113,8 +126,11 @@ getUserInfo session id = do ...@@ -113,8 +126,11 @@ getUserInfo session id = do
getAnnuaireContact :: Session -> Int -> AffRESTError AnnuaireContact getAnnuaireContact :: Session -> Int -> AffRESTError AnnuaireContact
getAnnuaireContact session id = do getAnnuaireContact session id = do
{ annuaire_contacts } <- queryGql session "get annuaire contact" $ eRes <- queryGql session "get annuaire contact" $
annuaireContactQuery `withVars` { id } annuaireContactQuery `withVars` { id }
case eRes of
Left err -> pure $ Left err
Right { annuaire_contacts } -> do
liftEffect $ here.log2 "[getAnnuaireContact] data" annuaire_contacts liftEffect $ here.log2 "[getAnnuaireContact] data" annuaire_contacts
pure $ case A.head annuaire_contacts of pure $ case A.head annuaire_contacts of
Nothing -> Left (CustomError $ "contact id=" <> show id <> " not found") Nothing -> Left (CustomError $ "contact id=" <> show id <> " not found")
...@@ -122,13 +138,19 @@ getAnnuaireContact session id = do ...@@ -122,13 +138,19 @@ getAnnuaireContact session id = do
getTreeFirstLevel :: Session -> Int -> AffRESTError TreeFirstLevel getTreeFirstLevel :: Session -> Int -> AffRESTError TreeFirstLevel
getTreeFirstLevel session id = do getTreeFirstLevel session id = do
{ tree } <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id } eRes <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id }
case eRes of
Left err -> pure $ Left err
Right { tree } -> do
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
pure $ Right tree -- TODO: error handling pure $ Right tree -- TODO: error handling
getTeam :: Session -> Int -> AffRESTError Team getTeam :: Session -> Int -> AffRESTError Team
getTeam session id = do getTeam session id = do
{ team } <- queryGql session "get team" $ teamQuery `withVars` { id } eRes <- queryGql session "get team" $ teamQuery `withVars` { id }
case eRes of
Left err -> pure $ Left err
Right { team } -> do
liftEffect $ here.log2 "[getTree] data" team liftEffect $ here.log2 "[getTree] data" team
pure $ Right team pure $ Right team
...@@ -154,7 +176,10 @@ deleteTeamMembership session sharedFolderId teamNodeId = do ...@@ -154,7 +176,10 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext
getNodeContext session context_id node_id = do getNodeContext session context_id node_id = do
let query = GQLCTX.nodeContextQuery `withVars` { context_id, node_id } let query = GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
{ contexts } <- queryGql session "get node context" query eRes <- queryGql session "get node context" query
case eRes of
Left err -> pure $ Left err
Right { contexts } -> do
--liftEffect $ here.log2 "[getNodeContext] node context" contexts --liftEffect $ here.log2 "[getNodeContext] node context" contexts
case A.head contexts of case A.head contexts of
Nothing -> pure $ Left $ CustomError "no node context found" Nothing -> pure $ Left $ CustomError "no node context found"
...@@ -165,10 +190,8 @@ getContextsForNgrams :: Session -> CorpusId -> Array String -> AffRESTError (Arr ...@@ -165,10 +190,8 @@ getContextsForNgrams :: Session -> CorpusId -> Array String -> AffRESTError (Arr
getContextsForNgrams session corpus_id ngrams_terms = do getContextsForNgrams session corpus_id ngrams_terms = do
let query = GQLCTX.contextsForNgramsQuery `withVars` { corpus_id let query = GQLCTX.contextsForNgramsQuery `withVars` { corpus_id
, ngrams_terms: GQLCTX.NgramsTerms ngrams_terms } , ngrams_terms: GQLCTX.NgramsTerms ngrams_terms }
{ contexts_for_ngrams } <- queryGql session "get contexts for ngrams" query eRes <- queryGql session "get contexts for ngrams" query
pure $ rmap _.contexts_for_ngrams eRes
pure $ Right contexts_for_ngrams
--pure $ Right contexts_for_ngrams
updateNodeContextCategory :: Session -> Int -> Int -> Int -> AffRESTError Int updateNodeContextCategory :: Session -> Int -> Int -> Int -> AffRESTError Int
updateNodeContextCategory session context_id node_id category = do updateNodeContextCategory session context_id node_id category = do
...@@ -186,8 +209,10 @@ updateNodeContextCategory session context_id node_id category = do ...@@ -186,8 +209,10 @@ updateNodeContextCategory session context_id node_id category = do
getLanguages :: Session -> AffRESTError (Map.Map Lang GQLNLP.LanguageProperties) getLanguages :: Session -> AffRESTError (Map.Map Lang GQLNLP.LanguageProperties)
getLanguages session = do getLanguages session = do
let query = GQLNLP.nlpQuery let query = GQLNLP.nlpQuery
{ languages } <- queryGql session "get languages" query eRes <- queryGql session "get languages" query
case eRes of
Left err -> pure $ Left err
Right { languages } -> do
liftEffect $ here.log2 "[getLanguages] languages" languages liftEffect $ here.log2 "[getLanguages] languages" languages
pure $ Right $ Map.fromFoldable $ (\{ key, value } -> Tuple key value) <$> languages pure $ Right $ Map.fromFoldable $ (\{ key, value } -> Tuple key value) <$> languages
...@@ -196,11 +221,11 @@ getContextNgrams :: Session -> Int -> Int -> AffRESTError (Array NgramsTerm) ...@@ -196,11 +221,11 @@ getContextNgrams :: Session -> Int -> Int -> AffRESTError (Array NgramsTerm)
getContextNgrams session context_id list_id = do getContextNgrams session context_id list_id = do
client <- liftEffect $ getClient session client <- liftEffect $ getClient session
let query = GQLCTX.contextNgramsQuery `withVars` { context_id, list_id } let query = GQLCTX.contextNgramsQuery `withVars` { context_id, list_id }
{ context_ngrams } <- queryGql session "get context ngrams" query eRes <- queryGql session "get context ngrams" query
pure $ Right $ NormNgramsTerm <$> context_ngrams pure $ rmap (\{ context_ngrams } -> NormNgramsTerm <$> context_ngrams) eRes
getBreadcrumb :: Session -> Int -> AffRESTError BreadcrumbInfo getBreadcrumb :: Session -> Int -> AffRESTError BreadcrumbInfo
getBreadcrumb session id = do getBreadcrumb session id = do
{ tree_branch } <- queryGql session "get breadcrumb branch" $ breadcrumbQuery `withVars` { id } eRes <- queryGql session "get breadcrumb branch" $ breadcrumbQuery `withVars` { id }
liftEffect $ here.log2 "[getBreadcrumb] breadcrumb" tree_branch -- liftEffect $ here.log2 "[getBreadcrumb] breadcrumb" tree_branch
pure $ Right tree_branch pure $ rmap _.tree_branch eRes
...@@ -56,6 +56,9 @@ instance Eq RESTError where ...@@ -56,6 +56,9 @@ instance Eq RESTError where
eq _ _ = false eq _ _ = false
type AffRESTError a = Aff (Either RESTError a)
data FrontendError = data FrontendError =
EC_400__node_creation_failed_insert_node { user_id :: Int EC_400__node_creation_failed_insert_node { user_id :: Int
, parent_id :: Int } , parent_id :: Int }
...@@ -176,8 +179,6 @@ logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e ...@@ -176,8 +179,6 @@ logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e
-- logRESTError here prefix (ReadJSONError e) = here.warn2 (prefix <> " ReadJSONError ") $ show e -- logRESTError here prefix (ReadJSONError e) = here.warn2 (prefix <> " ReadJSONError ") $ show e
-- logRESTError here prefix (CustomError e) = here.warn2 (prefix <> " CustomError ") $ e -- logRESTError here prefix (CustomError e) = here.warn2 (prefix <> " CustomError ") $ e
type AffRESTError a = Aff (Either RESTError a)
readJSON :: forall a. JSON.ReadForeign a readJSON :: forall a. JSON.ReadForeign a
=> Either Affjax.Error (Affjax.Response AC.Json) => Either Affjax.Error (Affjax.Response AC.Json)
......
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