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
8acf12ac
Commit
8acf12ac
authored
Nov 06, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] add authorization bearer to /gql queries
parent
ba24537c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+14
-6
Contact.purs
src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs
+3
-3
REST.purs
src/Gargantext/Config/REST.purs
+1
-1
No files found.
src/Gargantext/Components/GraphQL.purs
View file @
8acf12ac
module Gargantext.Components.GraphQL where
import Gargantext.Prelude
import Affjax.RequestHeader as ARH
import Data.Argonaut.Decode (JsonDecodeError)
import Data.Bifunctor (lmap)
import Data.List.Types (NonEmptyList)
...
...
@@ -8,7 +11,7 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.
Prelude
import Gargantext.
Sessions (Session(..))
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
...
...
@@ -40,17 +43,22 @@ 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 Mutation Void)
getClient = createClient { headers: [], url: "http://localhost:8008/gql" }
getClient :: Session -> Effect (Client UrqlClient Schema Mutation Void)
getClient (Session { token }) = createClient { headers, url: "http://localhost:8008/gql" }
where
headers = [ ARH.RequestHeader "Authorization" $ "Bearer " <> token ]
queryGql ::
forall query returns.
GqlQuery Schema query returns =>
JSON.ReadForeign returns =>
String -> query -> Aff returns
queryGql name q = do
Session
-> String
-> query
-> Aff returns
queryGql session name q = do
--query client name q
client <- liftEffect
getClient
client <- liftEffect
$ getClient session
gqlQuery (client :: Client UrqlClient Schema Mutation Void) name q
--query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
...
...
src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs
View file @
8acf12ac
...
...
@@ -225,7 +225,7 @@ saveUserInfo :: Session -> Int -> UserInfo -> Aff (Either RESTError Int)
saveUserInfo session id ui = do
-- TODO GraphQL
-- pure $ Left $ CustomError "TODO implement graphql for saveUserInfo"
client <- liftEffect $ getClient
client <- liftEffect $ getClient
session
res <- mutationOpts
(\m -> m)
client
...
...
@@ -320,7 +320,7 @@ getUserInfoWithReload {nodeId, session} = getUserInfo session nodeId -- getConta
getUserInfo :: Session -> Int -> Aff (Either RESTError UserInfo)
getUserInfo session id = do
{ user_infos } <- queryGql "get user infos"
{ user_infos } <- queryGql
session
"get user infos"
{ user_infos: { user_id: id } =>>
{ ui_id: unit
, ui_username: unit
...
...
@@ -383,7 +383,7 @@ getUserInfo session id = do
--
--getUser' :: Session -> Int -> Aff (Either RESTError ContactData)
--getUser' session id = do
-- { users } <- queryGql "get user"
-- { users } <- queryGql
session
"get user"
-- { users: { user_id: id } =>>
-- { u_id
-- , u_hyperdata:
...
...
src/Gargantext/Config/REST.purs
View file @
8acf12ac
...
...
@@ -152,7 +152,7 @@ postMultipartFormData mtoken url body = do
, ARH.Accept applicationJSON
] <>
foldMap (\token ->
[ ARH.RequestHeader "Authorization" $ "
Bearer
" <> token ]
[ ARH.RequestHeader "Authorization" $ " " <> token ]
) mtoken
, content = Just $ formData fd
}
...
...
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