Endpoints.purs 1.69 KB
Newer Older
1 2
module Gargantext.Components.GraphQL.Endpoints where

3 4 5 6
import Gargantext.Components.GraphQL.Node
import Gargantext.Components.GraphQL.User
import Gargantext.Prelude

7 8 9
import Data.Array as A
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
10
import Data.Unit (unit)
11 12
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
13
import Gargantext.Components.GraphQL (getClient, queryGql)
14
import Gargantext.Components.GraphQL.Task as GQLT
15
import Gargantext.Config.REST (AffRESTError, RESTError(..))
16
import Gargantext.Sessions (Session)
17
import Gargantext.Types (AsyncTaskWithType(..), AsyncTask(..), AsyncTaskType(..), NodeType)
18
import Gargantext.Utils.Reactix as R2
19
import GraphQL.Client.Args (onlyArgs, (=>>))
20
import GraphQL.Client.Query (mutation)
21
import GraphQL.Client.Variables (withVars)
22
import Simple.JSON as JSON
23 24 25 26 27 28 29 30 31 32 33 34

here :: R2.Here
here = R2.here "Gargantext.Components.GraphQL.Endpoints"

getNodeParent :: Session -> Int -> NodeType -> Aff (Array Node)
getNodeParent session nodeId parentType = do
  { node_parent } <- queryGql session "get node parent" $
                     nodeParentQuery `withVars` { id: nodeId
                                                , parent_type: show parentType }  -- TODO: remove "show"
  liftEffect $ here.log2 "[getNodeParent] node_parent" node_parent
  pure $ node_parent

35
getUserInfo :: Session -> Int -> AffRESTError UserInfo
36 37 38 39 40 41 42
getUserInfo session id = do
  { user_infos } <- queryGql session "get user infos" $ userInfoQuery `withVars` { id }
  liftEffect $ here.log2 "[getUserInfo] user infos" user_infos
  pure $ case A.head user_infos of
    Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
    -- NOTE Contact is at G.C.N.A.U.C.Types
    Just ui -> Right ui
43