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
Show 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
module Gargantext.Components.GraphQL where
import Gargantext.Prelude
import Affjax.RequestHeader as ARH
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)
...
@@ -8,7 +11,7 @@ import Effect.Aff (Aff)
...
@@ -8,7 +11,7 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError)
import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.
Prelude
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)
...
@@ -40,17 +43,22 @@ gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError
...
@@ -40,17 +43,22 @@ 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 Mutation Void)
getClient :: Session -> Effect (Client UrqlClient Schema Mutation Void)
getClient = createClient { headers: [], url: "http://localhost:8008/gql" }
getClient (Session { token }) = createClient { headers, url: "http://localhost:8008/gql" }
where
headers = [ ARH.RequestHeader "Authorization" $ "Bearer " <> token ]
queryGql ::
queryGql ::
forall query returns.
forall query returns.
GqlQuery Schema query returns =>
GqlQuery Schema query returns =>
JSON.ReadForeign returns =>
JSON.ReadForeign returns =>
String -> query -> Aff returns
Session
queryGql name q = do
-> String
-> query
-> Aff returns
queryGql session name q = do
--query client name q
--query client name q
client <- liftEffect
getClient
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)
--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)
...
@@ -225,7 +225,7 @@ 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
client <- liftEffect $ getClient
session
res <- mutationOpts
res <- mutationOpts
(\m -> m)
(\m -> m)
client
client
...
@@ -320,7 +320,7 @@ getUserInfoWithReload {nodeId, session} = getUserInfo session nodeId -- getConta
...
@@ -320,7 +320,7 @@ getUserInfoWithReload {nodeId, session} = getUserInfo session nodeId -- getConta
getUserInfo :: Session -> Int -> Aff (Either RESTError UserInfo)
getUserInfo :: Session -> Int -> Aff (Either RESTError UserInfo)
getUserInfo session id = do
getUserInfo session id = do
{ user_infos } <- queryGql "get user infos"
{ user_infos } <- queryGql
session
"get user infos"
{ user_infos: { user_id: id } =>>
{ user_infos: { user_id: id } =>>
{ ui_id: unit
{ ui_id: unit
, ui_username: unit
, ui_username: unit
...
@@ -383,7 +383,7 @@ getUserInfo session id = do
...
@@ -383,7 +383,7 @@ getUserInfo session id = do
--
--
--getUser' :: Session -> Int -> Aff (Either RESTError ContactData)
--getUser' :: Session -> Int -> Aff (Either RESTError ContactData)
--getUser' session id = do
--getUser' session id = do
-- { users } <- queryGql "get user"
-- { users } <- queryGql
session
"get user"
-- { users: { user_id: id } =>>
-- { users: { user_id: id } =>>
-- { u_id
-- { u_id
-- , u_hyperdata:
-- , u_hyperdata:
...
...
src/Gargantext/Config/REST.purs
View file @
8acf12ac
...
@@ -152,7 +152,7 @@ postMultipartFormData mtoken url body = do
...
@@ -152,7 +152,7 @@ postMultipartFormData mtoken url body = do
, ARH.Accept applicationJSON
, ARH.Accept applicationJSON
] <>
] <>
foldMap (\token ->
foldMap (\token ->
[ ARH.RequestHeader "Authorization" $ "
Bearer
" <> token ]
[ ARH.RequestHeader "Authorization" $ " " <> token ]
) mtoken
) mtoken
, content = Just $ formData fd
, 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