Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-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
Przemyslaw Kaminski
haskell-gargantext
Commits
b3efe9cc
Commit
b3efe9cc
authored
Nov 16, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] more asynctask work
parent
347f323c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
14 deletions
+34
-14
Types.hs
src/Gargantext/API/Admin/Orchestrator/Types.hs
+3
-4
GraphQL.hs
src/Gargantext/API/GraphQL.hs
+12
-6
AsyncTask.hs
src/Gargantext/API/GraphQL/AsyncTask.hs
+17
-4
Prelude.hs
src/Gargantext/API/Prelude.hs
+2
-0
No files found.
src/Gargantext/API/Admin/Orchestrator/Types.hs
View file @
b3efe9cc
...
...
@@ -88,13 +88,13 @@ instance Arbitrary ScraperEvent where
arbitrary
=
ScraperEvent
<$>
elements
[
Nothing
,
Just
"test message"
]
<*>
elements
[
Nothing
,
Just
"INFO"
,
Just
"WARN"
]
<*>
elements
[
Nothing
,
Just
"2018-04-18"
]
instance
ToJSON
ScraperEvent
where
toJSON
=
genericToJSON
$
jsonOptions
"_scev_"
instance
FromJSON
ScraperEvent
where
parseJSON
=
genericParseJSON
$
jsonOptions
"_scev_"
instance
ToSchema
ScraperEvent
-- TODO _scev_ prefix
instance
GQLType
ScraperEvent
where
typeOptions
_
=
GQLU
.
unPrefix
"_scev_"
data
JobLog
=
JobLog
...
...
@@ -122,7 +122,6 @@ instance GQLType JobLog where
typeOptions
_
=
GQLU
.
unPrefix
"_scst_"
instance
ToSchema
ScraperInput
-- TODO _scin_ prefix
instance
ToSchema
ScraperEvent
-- TODO _scev_ prefix
instance
ToParamSchema
Offset
-- where
-- toParamSchema = panic "TODO"
...
...
src/Gargantext/API/GraphQL.hs
View file @
b3efe9cc
...
...
@@ -49,6 +49,9 @@ import qualified Data.Text.Lazy as LT
import
Data.Text.Lazy.Encoding
(
decodeUtf8
)
import
Data.Typeable
(
Typeable
)
import
Gargantext.API.Admin.Auth.Types
(
AuthenticatedUser
)
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
)
import
Gargantext.API.Prelude
(
HasJobEnv
'
)
import
qualified
Gargantext.API.GraphQL.AsyncTask
as
GQLAT
import
qualified
Gargantext.API.GraphQL.User
as
GQLUser
import
qualified
Gargantext.API.GraphQL.UserInfo
as
GQLUserInfo
import
Gargantext.API.Prelude
(
GargServerT
,
GargM
,
GargError
,
_ServerError
)
...
...
@@ -82,7 +85,8 @@ import qualified Servant.Auth.Server as SAS
-- | Represents possible GraphQL queries.
data
Query
m
=
Query
{
user_infos
::
GQLUserInfo
.
UserInfoArgs
->
m
[
GQLUserInfo
.
UserInfo
]
{
job_logs
::
GQLAT
.
JobLogArgs
->
m
[
JobLog
]
,
user_infos
::
GQLUserInfo
.
UserInfoArgs
->
m
[
GQLUserInfo
.
UserInfo
]
,
users
::
GQLUser
.
UserArgs
->
m
[
GQLUser
.
User
m
]
}
deriving
(
Generic
,
GQLType
)
...
...
@@ -109,18 +113,19 @@ data Contet m
-- | The main GraphQL resolver: how queries, mutations and
-- subscriptions are handled.
rootResolver
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
,
HasJobEnv'
env
)
=>
RootResolver
(
GargM
env
GargError
)
e
Query
Mutation
Undefined
rootResolver
=
RootResolver
{
queryResolver
=
Query
{
user_infos
=
GQLUserInfo
.
resolveUserInfos
{
queryResolver
=
Query
{
job_logs
=
GQLAT
.
resolveJobLogs
,
user_infos
=
GQLUserInfo
.
resolveUserInfos
,
users
=
GQLUser
.
resolveUsers
}
,
mutationResolver
=
Mutation
{
update_user_info
=
GQLUserInfo
.
updateUserInfo
}
,
subscriptionResolver
=
Undefined
}
-- | Main GraphQL "app".
app
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
,
HasJobEnv'
env
)
=>
App
(
EVENT
(
GargM
env
GargError
))
(
GargM
env
GargError
)
app
=
deriveApp
rootResolver
...
...
@@ -161,7 +166,8 @@ type API = SA.Auth '[SA.JWT, SA.Cookie] AuthenticatedUser
-- | Implementation of our API.
--api :: Server API
api
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
,
HasJobEnv'
env
)
=>
ServerT
API
(
GargM
env
GargError
)
api
(
SAS
.
Authenticated
_auser
)
=
httpPubApp
[]
app
:<|>
pure
httpPlayground
api
_
=
panic
"401 in graphql"
--SAS.throwAll (_ServerError # err401)
--api _ = panic "401 in graphql" --SAS.throwAll (_ServerError # err401)
api
_
=
httpPubApp
[]
app
:<|>
pure
httpPlayground
src/Gargantext/API/GraphQL/AsyncTask.hs
View file @
b3efe9cc
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}
module
Gargantext.API.GraphQL.AsyncTask
where
import
Control.Concurrent.MVar
(
readMVar
)
import
Control.Lens
import
Control.Monad.Base
(
liftBase
)
import
Control.Monad.Reader
(
ask
,
liftIO
)
import
Data.Morpheus.Types
(
GQLType
,
Resolver
...
...
@@ -14,12 +18,14 @@ import Data.Morpheus.Types
import
Data.Text
(
Text
)
import
qualified
Data.Text
as
T
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
))
import
Gargantext.API.Prelude
(
GargM
,
GargError
)
import
Gargantext.API.Prelude
(
GargM
,
GargError
,
HasJobEnv
'
)
import
Gargantext.Core.Mail.Types
(
HasMail
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
(
..
))
import
Gargantext.Database.Prelude
(
HasConnectionPool
,
HasConfig
)
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
Servant.Job.Async
(
HasJobEnv
(
job_env
),
jenv_jobs
)
import
Servant.Job.Core
(
env_map
,
env_state_mvar
)
data
JobLogArgs
=
JobLogArgs
...
...
@@ -29,12 +35,19 @@ data JobLogArgs
type
GqlM
e
env
=
Resolver
QUERY
e
(
GargM
env
GargError
)
resolveJobLogs
::
(
HasConnectionPool
env
,
HasConfig
env
)
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasJobEnv'
env
)
=>
JobLogArgs
->
GqlM
e
env
[
JobLog
]
resolveJobLogs
JobLogArgs
{
job_log_id
}
=
dbJobLogs
job_log_id
dbJobLogs
::
(
HasConnectionPool
env
,
HasConfig
env
)
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasJobEnv'
env
)
=>
Int
->
GqlM
e
env
[
JobLog
]
dbJobLogs
job_log_id
=
do
getJobLogs
job_log_id
--getJobLogs job_log_id
env
<-
ask
_
<-
lift
$
do
--val <- liftBase $ readMVar $ env ^. job_env . jenv_jobs . env_state_mvar
let
val
=
env
^.
job_env
printDebug
"[dbJobLogs] env ^. job_env ^. jenv_jobs"
val
printDebug
"[dbJobLogs] job_log_id"
job_log_id
pure
[]
src/Gargantext/API/Prelude.hs
View file @
b3efe9cc
...
...
@@ -50,6 +50,8 @@ class HasJoseError e where
joseError
::
(
MonadError
e
m
,
HasJoseError
e
)
=>
Jose
.
Error
->
m
a
joseError
=
throwError
.
(
_JoseError
#
)
type
HasJobEnv'
env
=
HasJobEnv
env
JobLog
JobLog
type
EnvC
env
=
(
HasConnectionPool
env
,
HasSettings
env
-- TODO rename HasDbSettings
...
...
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