Commit cd39004e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graphql] first draft for mutations

parent 00098c86
......@@ -3,6 +3,7 @@ module Gargantext.Components.GraphQL where
import Data.Argonaut.Decode (JsonDecodeError)
import Data.Bifunctor (lmap)
import Data.List.Types (NonEmptyList)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError)
......@@ -39,6 +40,9 @@ gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError
toJsonError :: NonEmptyList ForeignError -> JsonDecodeError
toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish
getClient :: Effect (Client UrqlClient Schema Void Void)
getClient = createClient { headers: [], url: "http://localhost:8008/gql" }
queryGql ::
forall query returns.
GqlQuery Schema query returns =>
......@@ -46,7 +50,7 @@ queryGql ::
String -> query -> Aff returns
queryGql name q = do
--query client name q
client <- liftEffect $ createClient { headers: [], url: "http://localhost:8008/gql" }
client <- liftEffect getClient
gqlQuery (client :: Client UrqlClient Schema Void Void) name q
--query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
......
......@@ -20,7 +20,7 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Data (Boxes)
import Gargantext.Components.GraphQL (queryGql)
import Gargantext.Components.GraphQL (getClient, queryGql)
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs as Tabs
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact'(..), ContactData', ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser)
......@@ -33,7 +33,8 @@ import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import GraphQL.Client.Args (type (==>), (=>>))
import GraphQL.Client.Args (type (==>), (=>>), onlyArgs)
import GraphQL.Client.Query (mutationOpts)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
......@@ -223,7 +224,13 @@ saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "")
saveUserInfo :: Session -> Int -> UserInfo -> Aff (Either RESTError Int)
saveUserInfo session id ui = do
-- TODO GraphQL
pure $ Left $ CustomError "TODO implement graphql for saveUserInfo"
--pure $ Left $ CustomError "TODO implement graphql for saveUserInfo"
client <- liftEffect $ getClient
mutationOpts
(\m -> m)
client
"update user_info"
{ update_user_info: onlyArgs { ui_id: id } }
type AnnuaireLayoutProps = ( annuaireId :: Int, session :: Session | ReloadProps )
......
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