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 ...@@ -3,6 +3,7 @@ module Gargantext.Components.GraphQL where
import Data.Argonaut.Decode (JsonDecodeError) import Data.Argonaut.Decode (JsonDecodeError)
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import Data.List.Types (NonEmptyList) import Data.List.Types (NonEmptyList)
import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError) import Foreign (unsafeToForeign, ForeignError)
...@@ -39,6 +40,9 @@ gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError ...@@ -39,6 +40,9 @@ gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError
toJsonError :: NonEmptyList ForeignError -> JsonDecodeError toJsonError :: NonEmptyList ForeignError -> JsonDecodeError
toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish 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 :: queryGql ::
forall query returns. forall query returns.
GqlQuery Schema query returns => GqlQuery Schema query returns =>
...@@ -46,7 +50,7 @@ queryGql :: ...@@ -46,7 +50,7 @@ queryGql ::
String -> query -> Aff returns String -> query -> Aff returns
queryGql name q = do queryGql name q = do
--query client name q --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 gqlQuery (client :: Client UrqlClient Schema Void Void) name q
--query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema) --query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
......
...@@ -20,7 +20,7 @@ import Effect (Effect) ...@@ -20,7 +20,7 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.App.Data (Boxes) 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.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs as Tabs 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) 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) ...@@ -33,7 +33,8 @@ import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2 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 as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
...@@ -223,7 +224,13 @@ saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "") ...@@ -223,7 +224,13 @@ saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "")
saveUserInfo :: Session -> Int -> UserInfo -> Aff (Either RESTError Int) saveUserInfo :: Session -> Int -> UserInfo -> Aff (Either RESTError Int)
saveUserInfo session id ui = do saveUserInfo session id ui = do
-- TODO GraphQL -- 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 ) 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