Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
9b48c285
Commit
9b48c285
authored
Jan 30, 2024
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/600-dev-wip-graphql-errors' into dev
parents
a75d8116
764bd7fb
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
306 additions
and
197 deletions
+306
-197
Add.purs
src/Gargantext/Components/Forest/Tree/Node/Action/Add.purs
+13
-14
Contact.purs
...argantext/Components/Forest/Tree/Node/Action/Contact.purs
+3
-3
Documentation.purs
...ext/Components/Forest/Tree/Node/Action/Documentation.purs
+8
-10
Download.purs
...rgantext/Components/Forest/Tree/Node/Action/Download.purs
+2
-4
Link.purs
src/Gargantext/Components/Forest/Tree/Node/Action/Link.purs
+7
-8
ManageTeam.purs
...antext/Components/Forest/Tree/Node/Action/ManageTeam.purs
+33
-25
Box.purs
src/Gargantext/Components/Forest/Tree/Node/Box.purs
+2
-2
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+98
-25
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+129
-104
REST.purs
src/Gargantext/Config/REST.purs
+11
-2
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/Add.purs
View file @
9b48c285
...
@@ -76,7 +76,7 @@ addNodeViewCpt :: R.Component CreateNodeProps
...
@@ -76,7 +76,7 @@ addNodeViewCpt :: R.Component CreateNodeProps
addNodeViewCpt = here.component "addNodeView" cpt where
addNodeViewCpt = here.component "addNodeView" cpt where
cpt { dispatch
cpt { dispatch
, nodeTypes } _ = do
, nodeTypes } _ = do
let defaultNodeType = fromMaybe
Folde
r $ head nodeTypes
let defaultNodeType = fromMaybe
Erro
r $ head nodeTypes
nodeName <- T.useBox $ GT.prettyNodeType defaultNodeType
nodeName <- T.useBox $ GT.prettyNodeType defaultNodeType
nodeName' <- T.useLive T.unequal nodeName
nodeName' <- T.useLive T.unequal nodeName
nodeType <- T.useBox defaultNodeType
nodeType <- T.useBox defaultNodeType
...
@@ -85,43 +85,42 @@ addNodeViewCpt = here.component "addNodeView" cpt where
...
@@ -85,43 +85,42 @@ addNodeViewCpt = here.component "addNodeView" cpt where
hasChromeAgent' <- R.unsafeHooksEffect hasChromeAgent
hasChromeAgent' <- R.unsafeHooksEffect hasChromeAgent
let
let
action = AddNode nodeName' nodeType'
SettingsBox {edit} = settingsBox nodeType'
SettingsBox {edit} = settingsBox nodeType'
setNodeType' nt = do
setNodeType' nt = do
T.write_ (GT.prettyNodeType nt) nodeName
T.write_ (GT.prettyNodeType nt) nodeName
T.write_ nt nodeType
T.write_ nt nodeType
(maybeChoose /\ nt')
=
maybeChoose
=
if length nodeTypes > 1 then
if length nodeTypes > 1 then
[ Tools.formChoice { items: nodeTypes
[ Tools.formChoice { items: nodeTypes
, default: nodeType'
, default: nodeType'
, callback: setNodeType'
, callback: setNodeType'
, print: print hasChromeAgent' } []
, print: print hasChromeAgent' } []
]
/\ nodeType'
]
else
else
[ H.div {}
[ H.div {}
[H.text $ "Creating a node of type "
[H.text $ "Creating a node of type "
<> show defaultN
t
<> show defaultN
odeType
<> " with name:"
<> " with name:"
]
]
] /\ defaultNt
]
where
defaultNt = fromMaybe Error $ head nodeTypes
maybeEdit =
maybeEdit =
if edit then
if edit then
[ inputWithEnterWithKey {
[ inputWithEnterWithKey {
onBlur: \val -> T.write_ val nodeName
autoFocus: true
, onEnter: \_ -> launchAff_ $ dispatch (AddNode nodeName' nt')
, onValueChanged: \val -> T.write_ val nodeName
, autoFocus: true
, className: "form-control"
, className: "form-control"
, defaultValue: nodeName' -- (prettyNodeType nt')
, defaultValue: nodeName' -- (prettyNodeType nt')
, placeholder: nodeName' -- (prettyNodeType nt')
, type: "text"
, key: show nodeType'
, key: show nodeType'
, onBlur: \val -> T.write_ val nodeName
, onEnter: \_ -> launchAff_ $ dispatch action
, onValueChanged: \val -> T.write_ val nodeName
, placeholder: nodeName' -- (prettyNodeType nt')
, required: false
, required: false
, type: "text"
} ]
} ]
else []
else []
pure $ Tools.panelWithSubmitButton { action
: AddNode nodeName' nt'
pure $ Tools.panelWithSubmitButton { action
, dispatch
, dispatch
, mError: Nothing } (maybeChoose <> maybeEdit)
, mError: Nothing } (maybeChoose <> maybeEdit)
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Contact.purs
View file @
9b48c285
...
@@ -38,7 +38,7 @@ actionAddContactCpt = here.component "actionAddContact" cpt where
...
@@ -38,7 +38,7 @@ actionAddContactCpt = here.component "actionAddContact" cpt where
pure $
pure $
Tools.panelNoFooter { mError: Nothing }
Tools.panelNoFooter { mError: Nothing }
[ textInputBox
[ textInputBox
{ boxAction:
\p -> AddContact p
{ boxAction:
AddContact
, dispatch
, dispatch
, id
, id
, params: { firstname: "", lastname: "" } }
, params: { firstname: "", lastname: "" } }
...
@@ -56,7 +56,8 @@ textInputBox :: R2.Leaf TextInputBoxProps
...
@@ -56,7 +56,8 @@ textInputBox :: R2.Leaf TextInputBoxProps
textInputBox = R2.leaf textInputBoxCpt
textInputBox = R2.leaf textInputBoxCpt
textInputBoxCpt :: R.Component TextInputBoxProps
textInputBoxCpt :: R.Component TextInputBoxProps
textInputBoxCpt = here.component "textInputBox" cpt where
textInputBoxCpt = here.component "textInputBox" cpt where
cpt { boxAction, dispatch
cpt { boxAction
, dispatch
, params: { firstname, lastname } } _ = do
, params: { firstname, lastname } } _ = do
firstName <- T.useBox firstname
firstName <- T.useBox firstname
...
@@ -102,4 +103,3 @@ textInputBoxCpt = here.component "textInputBox" cpt where
...
@@ -102,4 +103,3 @@ textInputBoxCpt = here.component "textInputBox" cpt where
, on: { click: \_ -> submitF unit }
, on: { click: \_ -> submitF unit }
, title:"Submit"
, title:"Submit"
} []
} []
src/Gargantext/Components/Forest/Tree/Node/Action/Documentation.purs
View file @
9b48c285
...
@@ -23,17 +23,15 @@ actionDocCpt = here.component "actionDoc" cpt where
...
@@ -23,17 +23,15 @@ actionDocCpt = here.component "actionDoc" cpt where
cpt { nodeType } _ = do
cpt { nodeType } _ = do
pure $
pure $
Tools.panelNoFooter { mError: Nothing }
Tools.panelNoFooter { mError: Nothing }
([ infoTitle nodeType ]
([ H.div { style: {margin: "10px"}}
[ H.h3 {} [H.text "Documentation about " ]
, H.h3 {className: GT.fldr nodeType true}
[ H.span {className: "font-family-theme mx-1"}
[ H.text $ show nodeType ]
]
]
]
<> (map (\info -> H.p {} [ H.text info ]) $ docOf nodeType))
<> (map (\info -> H.p {} [ H.text info ]) $ docOf nodeType))
where
infoTitle :: NodeType -> R.Element
infoTitle nt = H.div { style: {margin: "10px"}}
[ H.h3 {} [H.text "Documentation about " ]
, H.h3 {className: GT.fldr nt true}
[ H.span {className: "font-family-theme mx-1"}
[ H.text $ show nt ]
]
]
-- | TODO add documentation of all NodeType
-- | TODO add documentation of all NodeType
docOf :: NodeType -> Array String
docOf :: NodeType -> Array String
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Download.purs
View file @
9b48c285
...
@@ -45,10 +45,9 @@ actionDownloadCorpusCpt = here.component "actionDownloadCorpus" cpt where
...
@@ -45,10 +45,9 @@ actionDownloadCorpusCpt = here.component "actionDownloadCorpus" cpt where
Tools.panelWithSubmitButtonHref { action: DownloadNode
Tools.panelWithSubmitButtonHref { action: DownloadNode
, href
, href
, mError: Nothing }
, mError: Nothing }
[ H.div {} [H.text
info
] ]
[ H.div {} [H.text
"Download as JSON"
] ]
where
where
href = url session $ Routes.NodeAPI GT.Corpus (Just id) "export"
href = url session $ Routes.NodeAPI GT.Corpus (Just id) "export"
info = "Download as JSON"
actionDownloadGraph :: R2.Component ActionDownload
actionDownloadGraph :: R2.Component ActionDownload
actionDownloadGraph = R.createElement actionDownloadGraphCpt
actionDownloadGraph = R.createElement actionDownloadGraphCpt
...
@@ -59,10 +58,9 @@ actionDownloadGraphCpt = here.component "actionDownloadGraph" cpt where
...
@@ -59,10 +58,9 @@ actionDownloadGraphCpt = here.component "actionDownloadGraph" cpt where
Tools.panelWithSubmitButtonHref { action: DownloadNode
Tools.panelWithSubmitButtonHref { action: DownloadNode
, href
, href
, mError: Nothing }
, mError: Nothing }
[ H.div {} [H.text
info
] ]
[ H.div {} [H.text
"Info about the Graph as GEXF format"
] ]
where
where
href = url session $ Routes.NodeAPI GT.Graph (Just id) "gexf"
href = url session $ Routes.NodeAPI GT.Graph (Just id) "gexf"
info = "Info about the Graph as GEXF format"
data NodeListDownloadFormat = NL_CSV | NL_JSON
data NodeListDownloadFormat = NL_CSV | NL_JSON
derive instance Eq NodeListDownloadFormat
derive instance Eq NodeListDownloadFormat
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Link.purs
View file @
9b48c285
...
@@ -41,15 +41,14 @@ linkNodeCpt = here.component "linkNode" cpt
...
@@ -41,15 +41,14 @@ linkNodeCpt = here.component "linkNode" cpt
action <- T.useBox (LinkNode { nodeType: Nothing, params: Nothing})
action <- T.useBox (LinkNode { nodeType: Nothing, params: Nothing})
pure $
pure $
linkNode' { action
linkNode' { action
, boxes
, boxes
, dispatch
, dispatch
, id
, id
, nodeType
, nodeType
, session
, session
, subTreeParams
, subTreeParams
} []
} []
type Props =
type Props =
( action :: T.Box Action
( action :: T.Box Action
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/ManageTeam.purs
View file @
9b48c285
...
@@ -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)
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,32 +60,32 @@ teamLayoutWrapper :: R2.Component TeamProps
...
@@ -55,32 +60,32 @@ 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
error <- T.useBox Nothing
team_members <- T.useBox team_members
team_members <- T.useBox team_members
error <- T.useBox Nothing
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
)
)
teamLayoutRows :: R2.Leaf TeamRowProps
teamLayoutRows :: R2.Leaf TeamRowProps
teamLayoutRows = R2.leaf teamLayoutRowsCpt
teamLayoutRows = R2.leaf teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamRowProps
teamLayoutRowsCpt :: R.Component TeamRowProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt {
team_members, nodeId, session, error
, team_owner_username } _ = do
cpt {
error, nodeId, session, team_members
, team_owner_username } _ = do
team_members' <- T.useLive T.unequal team_members
team_members' <- T.useLive T.unequal team_members
error' <- T.useLive T.unequal error
error' <- T.useLive T.unequal error
pure $
pure $
if null team_members' then
if null team_members' then
H.div { style: {margin: "10px"}}
H.div { style: {margin: "10px"}
}
[ H.h4 {} [H.text "Your team is empty, you can send some invitations."]]
[ H.h4 {} [H.text "Your team is empty, you can send some invitations."]
]
else
else
Tools.panelNoFooter { mError: error' }
Tools.panelNoFooter { mError: error' }
(makeLeader team_owner_username : (map makeTeam team_members'))
(makeLeader team_owner_username : (map makeTeam team_members'))
...
@@ -104,15 +109,18 @@ teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
...
@@ -104,15 +109,18 @@ teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
submit sharedFolderId _ = do
submit sharedFolderId _ = do
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
callback res =
callback res =
do
case res of
case res of
Left _ -> do
Left err -> do
_ <- liftEffect $ T.write (Just "Only the Team owner can remove users") error
here.log2 "[callback] error forking runAff" err
pure unit
T.write_ (Just "Error forking 'runAff_'") error
Right val ->
Right val -> do
here.log2 "[callback] val" val
case val of
case val of
Left _ -> do
-- Left (EC_403__user_not_authorized { msg }) -> do
pure unit
-- liftEffect $ T.write_ (Just msg) error
Left err -> do
T.write_ (Just $ show err) error
Right r -> do
Right r -> do
T.modify_ (filter (\tm -> tm.shared_folder_id /= r)) team_members
T.modify_ (filter (\tm -> tm.shared_folder_id /= r)) team_members
T.write_ Nothing error
T.write_ Nothing error
...
...
src/Gargantext/Components/Forest/Tree/Node/Box.purs
View file @
9b48c285
...
@@ -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 } _ =
...
...
src/Gargantext/Components/GraphQL.purs
View file @
9b48c285
...
@@ -3,13 +3,19 @@ module Gargantext.Components.GraphQL where
...
@@ -3,13 +3,19 @@ module Gargantext.Components.GraphQL where
import Gargantext.Prelude
import Gargantext.Prelude
import Affjax.RequestHeader as ARH
import Affjax.RequestHeader as ARH
import Control.Monad.Error.Class as Errors
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.List.Types (NonEmptyList)
import Data.List.Types (NonEmptyList)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff
, throwError, error
)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError)
import FFI.Simple ((.?))
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
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.IMT as GQLIMT
...
@@ -18,58 +24,125 @@ import Gargantext.Components.GraphQL.Node as GQLNode
...
@@ -18,58 +24,125 @@ import Gargantext.Components.GraphQL.Node as GQLNode
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, BreadcrumbInfo)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, BreadcrumbInfo)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM, UserPubmedAPIKeyM, UserEPOAPIUserM, UserEPOAPITokenM)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM, UserPubmedAPIKeyM, UserEPOAPIUserM, UserEPOAPITokenM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
-- import Gargantext.Config.REST (AffRESTError, FrontendError, RESTError(..))
import Gargantext.Config.REST as REST
import Gargantext.Ends (Backend(..))
import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..))
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 (queryWithDecoder)
-- import GraphQL.Client.Operation (OpMutation)
import GraphQL.Client.Types (class GqlQuery, Client, class QueryClient)
import GraphQL.Client.Query (queryFullRes, queryWithDecoder, decodeGqlRes, getFullRes, queryFullRes) --, mutationJson)
import GraphQL.Client.SafeQueryName (safeQueryName)
import GraphQL.Client.ToGqlString (toGqlQueryString)
import GraphQL.Client.Types (class GqlQuery, GqlRes, Client(..), class QueryClient, clientQuery, defQueryOpts, clientMutation, defMutationOpts)
import GraphQL.Client.Variables (class VarsTypeChecked, getVarsJson, getVarsTypeNames)
import Simple.JSON as JSON
import Simple.JSON as JSON
import Type.Proxy (Proxy(..))
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
here :: R2.Here
here :: R2.Here
here = R2.here "Gargantext.Components.GraphQL"
here = R2.here "Gargantext.Components.GraphQL"
--client :: Client AffjaxClient Schema Void Void
--client = Client $ AffjaxClient "http://localhost:8008/gql" []
-- | Run a graphQL query with a custom decoder and custom options
-- TODO Rewrite this to REST.RESTError
type E a = Either JsonDecodeError a
-- | Run a graphQL query with a custom decoder
gqlQuery ::
gqlQuery ::
forall client schema query returns a b queryOpts mutationOpts.
forall client schema query returns a b queryOpts mutationOpts
QueryClient client queryOpts mutationOpts =>
. QueryClient client queryOpts mutationOpts
GqlQuery schema query returns =>
=> GqlQuery schema query returns
JSON.ReadForeign returns =>
-- VarsTypeChecked query =>
=> JSON.ReadForeign returns
--(queryOpts -> queryOpts) ->
--(queryOpts -> queryOpts) ->
(Client client schema a b) ->
=> Client client schema a b
String ->
-> String
query ->
-> query
Aff returns
-> REST.AffRESTError returns
gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError)
gqlQuery c@(Client client) queryNameUnsafe q = do
let opts = defQueryOpts client
json <- clientQuery opts client queryName (getVarsTypeNames q <> toGqlQueryString q) (getVarsJson q)
pure $ parseGQLJson json
where
queryName = safeQueryName queryNameUnsafe
-- | Run a graphQL mutation with a custom decoder
gqlMutation ::
forall client schema query returns qOpts mOpts a b
. QueryClient client qOpts mOpts
=> GqlQuery schema query returns
=> VarsTypeChecked query
=> JSON.ReadForeign returns
=> Client client a schema b
-> Proxy schema
-> String
-> query
-> REST.AffRESTError returns
gqlMutation c@(Client client) _ queryNameUnsafe q = do
let opts = defMutationOpts client
json <- clientMutation opts client queryName (getVarsTypeNames q <> toGqlQueryString q) (getVarsJson q)
toJsonError :: NonEmptyList ForeignError -> JsonDecodeError
liftEffect $ here.log2 "[gqlMutation] json" json
pure $ parseGQLJson json
where
queryName = safeQueryName queryNameUnsafe
parseGQLJson json =
-- NOTE 'json' contains interesting data, in particular the gql operation, error, etc
case json .? "error" of
-- what 'decodeGqlRes' does is take 'json.data' and decode it using our custom decode function
Nothing -> lmap (REST.ReadJSONError <<< unsafeCoerce) (decodeGqlRes decodeFn json)
Just err ->
-- Surely, an error must be returned, but which one?
Left $ case err .? "graphQLErrors" of
Nothing -> REST.CustomError "[gqlQuery] no 'graphQLErrors'"
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 = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish
toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish
getClient :: Session -> Effect (Client UrqlClient Schema Mutation Void)
getClient :: Session -> Effect (Client UrqlClient Schema Mutation Void)
getClient (Session { token, backend: Backend b }) = createClient { headers, url: b.baseUrl <> "/gql" }
getClient (Session { token, backend: Backend b }) = createClient { headers, url: b.baseUrl <> "/gql" }
where
where
headers = [ ARH.RequestHeader "Authorization" $ "Bearer " <> token ]
headers = [ ARH.RequestHeader "Authorization" $ "Bearer " <> token
, ARH.RequestHeader "X-Garg-Error-Scheme" $ "new" ]
queryGql ::
queryGql ::
forall query returns
.
forall query returns
GqlQuery Schema query returns =>
. GqlQuery Schema query returns
JSON.ReadForeign returns =>
=> JSON.ReadForeign returns
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
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
gqlQuery (client :: Client UrqlClient Schema Mutation Void) name q
gqlQuery (client :: Client UrqlClient Schema Mutation Void) name q
--query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
mutationGql ::
forall query returns
. GqlQuery Mutation query returns
=> JSON.ReadForeign returns
=> Session
-> String
-> query
-> REST.AffRESTError returns
mutationGql session name q = do
client <- liftEffect $ getClient session
gqlMutation (client :: Client UrqlClient Schema Mutation Void) (Proxy :: Proxy Mutation) name q
-- mutationJson (defQueryOpts client) (client :: Client UrqlClient Schema Mutation Void) name q
-- Schema
-- Schema
type Schema
type Schema
...
...
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
9b48c285
...
@@ -3,13 +3,14 @@ module Gargantext.Components.GraphQL.Endpoints where
...
@@ -3,13 +3,14 @@ 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
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (
getClient, query
Gql)
import Gargantext.Components.GraphQL (
E, getClient, queryGql, mutation
Gql)
import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.IMT as GQLIMT
...
@@ -25,7 +26,6 @@ import Gargantext.Sessions (Session(..))
...
@@ -25,7 +26,6 @@ import Gargantext.Sessions (Session(..))
import Gargantext.Types (CorpusId, NodeType)
import Gargantext.Types (CorpusId, NodeType)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars)
import GraphQL.Client.Variables (withVars)
here :: R2.Here
here :: R2.Here
...
@@ -33,104 +33,123 @@ here = R2.here "Gargantext.Components.GraphQL.Endpoints"
...
@@ -33,104 +33,123 @@ 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
liftEffect $ here.log2 "[getNode] node" nodes
Left err -> pure $ Left err
pure $ case A.head nodes of
Right { nodes } -> do
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
liftEffect $ here.log2 "[getNode] node" nodes
Just node -> Right node
pure $ case A.head nodes of
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
Just node -> Right node
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 }
liftEffect $ here.log2 "[getNodesCorpus] nodes_corpus" nodes_corpus
case eRes of
pure $ case A.head nodes_corpus of
Left err -> pure $ Left err
Nothing -> Left (CustomError $ "corpus with id" <> show corpusId <>" not found")
Right { nodes_corpus } -> do
Just corpus -> Right corpus
liftEffect $ here.log2 "[getNodesCorpus] nodes_corpus" nodes_corpus
pure $ case A.head nodes_corpus of
getNodeParent :: Session -> Int -> NodeType -> Aff (Array Node)
Nothing -> Left (CustomError $ "corpus with id" <> show corpusId <>" not found")
Just corpus -> Right corpus
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 }
liftEffect $ here.log2 "[getUser] users" users
case eRes of
pure $ case A.head users of
Left err -> pure $ Left err
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
Right { users } -> do
Just u -> Right u
liftEffect $ here.log2 "[getUser] users" users
pure $ case A.head users of
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
Just u -> Right u
updateUserPubmedAPIKey :: Session -> Int -> String -> AffRESTError Unit
updateUserPubmedAPIKey :: Session -> Int -> String -> AffRESTError Unit
updateUserPubmedAPIKey session user_id api_key = do
updateUserPubmedAPIKey session user_id api_key = do
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
{ update_user_pubmed_api_key } <- mutat
ion
eRes <- mutationGql sess
ion
client
"update_user_pubmed_api_key"
"update_user_pubmed_api_key"
{ update_user_pubmed_api_key: onlyArgs { user_id
{ update_user_pubmed_api_key: onlyArgs { user_id
, api_key } }
, api_key }
}
-- { update_user_pubmed_api_key
}
pure $
Right unit
pure $
rmap (const unit) eRes
updateUserEPOAPIUser :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIUser :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIUser session user_id api_user = do
updateUserEPOAPIUser session user_id api_user = do
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
{ update_user_epo_api_user } <- mutation
eRes <- mutationGql session
client
"update_user_epo_api_user"
"update_user_epo_api_user"
{ update_user_epo_api_user: onlyArgs { user_id
{ update_user_epo_api_user: onlyArgs { user_id
, api_user } }
, api_user } }
pure $ rmap (const unit) eRes
pure $ Right unit
updateUserEPOAPIToken :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIToken :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIToken session user_id api_token = do
updateUserEPOAPIToken session user_id api_token = do
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
{ update_user_epo_api_token } <- mutation
eRes <- mutationGql session
client
"update_user_epo_api_token"
"update_user_epo_api_token"
{ update_user_epo_api_token: onlyArgs { user_id
{ update_user_epo_api_token: onlyArgs { user_id
, api_token } }
, api_token } }
pure $ rmap (const unit) eRes
pure $ Right unit
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 }
liftEffect $ here.log2 "[getUserInfo] user infos" user_infos
case eRes of
pure $ case A.head user_infos of
Left err -> pure $ Left err
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
Right { user_infos } -> do
-- NOTE Contact is at G.C.N.A.U.C.Types
liftEffect $ here.log2 "[getUserInfo] user infos" user_infos
Just ui -> Right ui
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
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 }
liftEffect $ here.log2 "[getAnnuaireContact] data" annuaire_contacts
case eRes of
pure $ case A.head annuaire_contacts of
Left err -> pure $ Left err
Nothing -> Left (CustomError $ "contact id=" <> show id <> " not found")
Right { annuaire_contacts } -> do
Just r -> Right r
liftEffect $ here.log2 "[getAnnuaireContact] data" annuaire_contacts
pure $ case A.head annuaire_contacts of
Nothing -> Left (CustomError $ "contact id=" <> show id <> " not found")
Just r -> Right r
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 }
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
case eRes of
pure $ Right tree -- TODO: error handling
Left err -> pure $ Left err
Right { tree } -> do
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
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 }
liftEffect $ here.log2 "[getTree] data" team
case eRes of
pure $ Right team
Left err -> pure $ Left err
Right { team } -> do
liftEffect $ here.log2 "[getTree] data" team
pure $ Right team
type SharedFolderId = Int
type SharedFolderId = Int
type TeamNodeId = Int
type TeamNodeId = Int
...
@@ -139,68 +158,74 @@ deleteTeamMembership :: Session -> SharedFolderId -> TeamNodeId -> AffRESTError
...
@@ -139,68 +158,74 @@ deleteTeamMembership :: Session -> SharedFolderId -> TeamNodeId -> AffRESTError
deleteTeamMembership session sharedFolderId teamNodeId = do
deleteTeamMembership session sharedFolderId teamNodeId = do
let token = getToken session
let token = getToken session
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
{ delete_team_membership } <- mutation
eRes <- mutationGql session
client
"delete_team_membership"
"delete_team_membership"
{ delete_team_membership: onlyArgs { token: token
{ delete_team_membership: onlyArgs { token: token
, shared_folder_id: sharedFolderId
, shared_folder_id: sharedFolderId
, team_node_id: teamNodeId } }
, team_node_id: teamNodeId } }
pure $ case eRes of
pure $ case A.head delete_team_membership of
Left err -> Left err
Nothing -> Left (CustomError $ "Failed to delete team membership. team node id=" <> show teamNodeId <> " shared folder id=" <> show sharedFolderId)
Right { delete_team_membership } ->
Just _ -> Right sharedFolderId
case A.head delete_team_membership of
Nothing -> Left (CustomError $ "Failed to delete team membership. team node id=" <> show teamNodeId <> " shared folder id=" <> show sharedFolderId)
Just _ -> Right sharedFolderId
where
where
getToken (Session { token }) = token
getToken (Session { token }) = token
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
--liftEffect $ here.log2 "[getNodeContext] node context" contexts
case eRes of
case A.head contexts of
Left err -> pure $ Left err
Nothing -> pure $ Left $ CustomError "no node context found"
Right { contexts } -> do
Just context -> pure $ Right context -- TODO: error handling
--liftEffect $ here.log2 "[getNodeContext] node context" contexts
case A.head contexts of
Nothing -> pure $ Left $ CustomError "no node context found"
Just context -> pure $ Right context -- TODO: error handling
type ContextsForNgramsGQL = { contexts_for_ngrams :: Array GQLCTX.Context }
type ContextsForNgramsGQL = { contexts_for_ngrams :: Array GQLCTX.Context }
getContextsForNgrams :: Session -> CorpusId -> Array String -> AffRESTError (Array GQLCTX.Context)
getContextsForNgrams :: Session -> CorpusId -> Array String -> AffRESTError (Array GQLCTX.Context)
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
client <- liftEffect $ getClient session
client <- liftEffect $ getClient session
{ update_node_context_category } <- mutation
eRes <- mutationGql session
client
"update_node_context_category"
"update_node_context_category"
{ update_node_context_category: onlyArgs { context_id
{ update_node_context_category: onlyArgs { context_id
, node_id
, node_id
, category } }
, category } }
pure $ case eRes of
pure $ case A.head update_node_context_category of
Left err -> Left err
Nothing -> Left (CustomError $ "Failed to update node category")
Right { update_node_context_category } -> case A.head update_node_context_category of
Just _ -> Right context_id
Nothing -> Left (CustomError $ "Failed to update node category")
Just _ -> Right context_id
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
liftEffect $ here.log2 "[getLanguages] languages" languages
Left err -> pure $ Left err
Right { languages } -> do
pure $ Right $ Map.fromFoldable $ (\{ key, value } -> Tuple key value) <$> languages
liftEffect $ here.log2 "[getLanguages] languages" languages
pure $ Right $ Map.fromFoldable $ (\{ key, value } -> Tuple key value) <$> languages
getContextNgrams :: Session -> Int -> Int -> AffRESTError (Array NgramsTerm)
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_ngram
s
pure $
rmap (\{ context_ngrams } -> NormNgramsTerm <$> context_ngrams) eRe
s
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
src/Gargantext/Config/REST.purs
View file @
9b48c285
...
@@ -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 }
...
@@ -69,6 +72,8 @@ data FrontendError =
...
@@ -69,6 +72,8 @@ data FrontendError =
| EC_403__login_failed_error { node_id :: Int
| EC_403__login_failed_error { node_id :: Int
, user_id :: Int }
, user_id :: Int }
| EC_403__login_failed_invalid_username_or_password
| EC_403__login_failed_invalid_username_or_password
| EC_403__user_not_authorized { user_id :: Int
, msg :: String }
| EC_404__node_context_not_found { context_id :: Int }
| EC_404__node_context_not_found { context_id :: Int }
| EC_404__node_lookup_failed_not_found { node_id :: Int }
| EC_404__node_lookup_failed_not_found { node_id :: Int }
| EC_404__node_lookup_failed_parent_not_found { node_id :: Int }
| EC_404__node_lookup_failed_parent_not_found { node_id :: Int }
...
@@ -94,6 +99,8 @@ instance Show FrontendError where
...
@@ -94,6 +99,8 @@ instance Show FrontendError where
"Login failed for node_id " <> show node_id <> ", user id " <> show user_id
"Login failed for node_id " <> show node_id <> ", user id " <> show user_id
show EC_403__login_failed_invalid_username_or_password =
show EC_403__login_failed_invalid_username_or_password =
"Invalid username or password"
"Invalid username or password"
show (EC_403__user_not_authorized { user_id, msg }) =
"User not authorized to perform action: " <> show user_id <> ". " <> msg
show (EC_404__node_context_not_found { context_id }) =
show (EC_404__node_context_not_found { context_id }) =
"Context not found with id " <> show context_id
"Context not found with id " <> show context_id
show (EC_404__node_lookup_failed_not_found { node_id }) =
show (EC_404__node_lookup_failed_not_found { node_id }) =
...
@@ -138,6 +145,10 @@ instance JSON.ReadForeign FrontendError where
...
@@ -138,6 +145,10 @@ instance JSON.ReadForeign FrontendError where
pure $ EC_403__login_failed_error { node_id, user_id }
pure $ EC_403__login_failed_error { node_id, user_id }
"EC_403__login_failed_invalid_username_or_password" -> do
"EC_403__login_failed_invalid_username_or_password" -> do
pure $ EC_403__login_failed_invalid_username_or_password
pure $ EC_403__login_failed_invalid_username_or_password
"EC_403__user_not_authorized" -> do
{ data: { user_id, msg } } <- JSON.readImpl f :: Foreign.F { data :: { user_id :: Int
, msg :: String } }
pure $ EC_403__user_not_authorized { user_id, msg }
"EC_404__node_context_not_found" -> do
"EC_404__node_context_not_found" -> do
{ data: { context_id } } <- JSON.readImpl f :: Foreign.F { data :: { context_id :: Int } }
{ data: { context_id } } <- JSON.readImpl f :: Foreign.F { data :: { context_id :: Int } }
pure $ EC_404__node_context_not_found { context_id }
pure $ EC_404__node_context_not_found { context_id }
...
@@ -168,8 +179,6 @@ logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e
...
@@ -168,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)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment