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
764bd7fb
Verified
Commit
764bd7fb
authored
Jan 30, 2024
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] mutation with support for errors
parent
1968de42
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
69 deletions
+101
-69
ManageTeam.purs
...antext/Components/Forest/Tree/Node/Action/ManageTeam.purs
+12
-10
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+51
-21
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+38
-38
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/ManageTeam.purs
View file @
764bd7fb
...
...
@@ -78,14 +78,14 @@ teamLayoutRows :: R2.Leaf TeamRowProps
teamLayoutRows = R2.leaf teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamRowProps
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
error' <- T.useLive T.unequal error
pure $
if null team_members' then
H.div { style: {margin: "10px"}}
[ H.h4 {} [H.text "Your team is empty, you can send some invitations."]]
H.div { style: {margin: "10px"}
}
[ H.h4 {} [H.text "Your team is empty, you can send some invitations."]
]
else
Tools.panelNoFooter { mError: error' }
(makeLeader team_owner_username : (map makeTeam team_members'))
...
...
@@ -109,16 +109,18 @@ teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
submit sharedFolderId _ = do
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
callback res =
callback res =
do
case res of
Left err -> do
here.log2 "[callback] error forking runAff" err
T.write_ (Just "Error forking 'runAff_'") error
Right val -> do
here.log2 "[callback] val" val
case val of
-- Left (EC_403__user_not_authorized { msg }) -> do
-- liftEffect $ T.write_ (Just msg) error
Left err -> do
liftEffect $ T.write_ (Just $ show err) error
Right val ->
case val of
Left _ -> do
pure unit
T.write_ (Just $ show err) error
Right r -> do
T.modify_ (filter (\tm -> tm.shared_folder_id /= r)) team_members
T.write_ Nothing error
...
...
src/Gargantext/Components/GraphQL.purs
View file @
764bd7fb
...
...
@@ -31,12 +31,14 @@ import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
import GraphQL.Client.Query (queryFullRes, queryWithDecoder, decodeGqlRes, getFullRes, queryFullRes)
-- import GraphQL.Client.Operation (OpMutation)
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)
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 Type.Proxy (Proxy(..))
import Unsafe.Coerce (unsafeCoerce)
...
...
@@ -47,30 +49,48 @@ here = R2.here "Gargantext.Components.GraphQL"
-- TODO Rewrite this to REST.RESTError
type E a = Either JsonDecodeError a
--client :: Client AffjaxClient Schema Void Void
--client = Client $ AffjaxClient "http://localhost:8008/gql" []
-- | Run a graphQL query with a custom decoder and custom options
-- | Run a graphQL query with a custom decoder
gqlQuery ::
forall client schema query returns a b queryOpts mutationOpts
.
QueryClient client queryOpts mutationOpts =>
GqlQuery schema query returns =>
forall client schema query returns a b queryOpts mutationOpts
. QueryClient client queryOpts mutationOpts
=> GqlQuery schema query returns
-- VarsTypeChecked query =>
JSON.ReadForeign returns =>
=> JSON.ReadForeign returns
--(queryOpts -> queryOpts) ->
(Client client schema a b) ->
String ->
query ->
REST.AffRESTError returns
=> Client client schema a b
-> String
-> query
->
REST.AffRESTError returns
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)
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
...
...
@@ -100,19 +120,29 @@ getClient (Session { token, backend: Backend b }) = createClient { headers, url:
, ARH.RequestHeader "X-Garg-Error-Scheme" $ "new" ]
queryGql ::
forall query returns
.
GqlQuery Schema query returns =>
JSON.ReadForeign returns =>
Session
forall query returns
. GqlQuery Schema query returns
=> JSON.ReadForeign returns
=>
Session
-> String
-> query
-> REST.AffRESTError returns
queryGql session name q = do
--query client name q
client <- liftEffect $ getClient session
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
type Schema
...
...
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
764bd7fb
...
...
@@ -10,7 +10,7 @@ import Data.Map as Map
import Data.Tuple (Tuple(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (E, getClient, queryGql)
import Gargantext.Components.GraphQL (E, getClient, queryGql
, mutationGql
)
import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
...
...
@@ -26,7 +26,6 @@ import Gargantext.Sessions (Session(..))
import Gargantext.Types (CorpusId, NodeType)
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars)
here :: R2.Here
...
...
@@ -85,32 +84,30 @@ getUser session id = do
updateUserPubmedAPIKey :: Session -> Int -> String -> AffRESTError Unit
updateUserPubmedAPIKey session user_id api_key = do
client <- liftEffect $ getClient session
{ update_user_pubmed_api_key } <- mutation
client
eRes <- mutationGql session
"update_user_pubmed_api_key"
{ update_user_pubmed_api_key: onlyArgs { user_id
, api_key } }
pure $ Right unit
-- { update_user_pubmed_api_key }
pure $ rmap (const unit) eRes
updateUserEPOAPIUser :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIUser session user_id api_user = do
client <- liftEffect $ getClient session
{ update_user_epo_api_user } <- mutation
client
eRes <- mutationGql session
"update_user_epo_api_user"
{ update_user_epo_api_user: onlyArgs { user_id
, api_user } }
pure $
Right unit
pure $
rmap (const unit) eRes
updateUserEPOAPIToken :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIToken session user_id api_token = do
client <- liftEffect $ getClient session
{ update_user_epo_api_token } <- mutation
client
eRes <- mutationGql session
"update_user_epo_api_token"
{ update_user_epo_api_token: onlyArgs { user_id
, api_token } }
pure $
Right unit
pure $
rmap (const unit) eRes
getUserInfo :: Session -> Int -> AffRESTError UserInfo
getUserInfo session id = do
...
...
@@ -161,13 +158,15 @@ deleteTeamMembership :: Session -> SharedFolderId -> TeamNodeId -> AffRESTError
deleteTeamMembership session sharedFolderId teamNodeId = do
let token = getToken session
client <- liftEffect $ getClient session
{ delete_team_membership } <- mutation
client
eRes <- mutationGql session
"delete_team_membership"
{ delete_team_membership: onlyArgs { token: token
, shared_folder_id: sharedFolderId
, team_node_id: teamNodeId } }
pure $ case A.head delete_team_membership of
pure $ case eRes of
Left err -> Left err
Right { delete_team_membership } ->
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
...
...
@@ -196,13 +195,14 @@ getContextsForNgrams session corpus_id ngrams_terms = do
updateNodeContextCategory :: Session -> Int -> Int -> Int -> AffRESTError Int
updateNodeContextCategory session context_id node_id category = do
client <- liftEffect $ getClient session
{ update_node_context_category } <- mutation
client
eRes <- mutationGql session
"update_node_context_category"
{ update_node_context_category: onlyArgs { context_id
, node_id
, category } }
pure $ case A.head update_node_context_category of
pure $ case eRes of
Left err -> Left err
Right { update_node_context_category } -> case A.head update_node_context_category of
Nothing -> Left (CustomError $ "Failed to update node category")
Just _ -> Right context_id
...
...
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