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
b947678a
Commit
b947678a
authored
Oct 18, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] some user work
NOTE: Does not compile
parent
7b9de040
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
32 deletions
+53
-32
GraphQL.hs
src/Gargantext/API/GraphQL.hs
+7
-31
User.hs
src/Gargantext/API/GraphQL/User.hs
+46
-0
User.hs
src/Gargantext/Database/Query/Table/User.hs
+0
-1
No files found.
src/Gargantext/API/GraphQL.hs
View file @
b947678a
...
...
@@ -14,6 +14,7 @@ import Data.ByteString.Lazy.Char8
(
ByteString
)
import
Data.List.NonEmpty
(
NonEmpty
((
:|
)))
import
Data.Maybe
(
fromMaybe
)
import
Data.Morpheus
(
App
,
deriveApp
)
...
...
@@ -48,16 +49,18 @@ import Data.Text (Text)
import
qualified
Data.Text.Lazy
as
LT
import
Data.Text.Lazy.Encoding
(
decodeUtf8
)
import
Data.Typeable
(
Typeable
)
import
Gargantext.API.GraphQL.User
import
Gargantext.API.Prelude
(
GargServerT
,
GargM
,
GargError
)
import
Gargantext.Database.Prelude
(
Cmd
,
HasConnectionPool
,
HasConfig
)
import
Gargantext.Database.Query.Table.User
(
getUsersWithId
)
import
Gargantext.Database.Schema.User
(
UserPoly
(
..
),
UserLight
)
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
GHC.TypeLits
import
Network.HTTP.Media
((
//
),
(
/:
))
import
Network.WebSockets
(
ServerApp
,
)
import
qualified
Prelude
as
Prelude
import
Servant
(
(
:<|>
)
(
..
),
(
:>
),
...
...
@@ -70,18 +73,11 @@ import Servant
ReqBody
,
ServerT
,
)
import
Prelude
-- | Represents possible GraphQL queries.
data
Query
m
=
Query
{
user
::
UserArgs
->
m
UserLight
}
deriving
(
Generic
,
GQLType
)
-- | Arguments to the "user" query.
data
UserArgs
=
UserArgs
{
user_id
::
Int
{
users
::
UserArgs
->
m
[
UserLight
]
}
deriving
(
Generic
,
GQLType
)
-- | Possible GraphQL Events, i.e. here we describe how we will
...
...
@@ -96,7 +92,7 @@ data Channel
-- | This type describes what data we will operate on.
data
Contet
=
UserContet
UserLight
=
UserContet
[
UserLight
]
-- | The main GraphQL resolver: how queries, mutations and
...
...
@@ -106,30 +102,10 @@ rootResolver
=>
RootResolver
(
GargM
env
GargError
)
EVENT
Query
Undefined
Undefined
rootResolver
=
RootResolver
{
queryResolver
=
Query
{
user
=
resolveUser
}
{
queryResolver
=
Query
{
user
s
=
resolveUsers
}
,
mutationResolver
=
Undefined
,
subscriptionResolver
=
Undefined
}
-- | Function to resolve user from a query.
resolveUser
::
(
HasConnectionPool
env
,
HasConfig
env
)
=>
UserArgs
->
ResolverQ
e
(
GargM
env
GargError
)
UserLight
resolveUser
UserArgs
{
user_id
}
=
do
liftEither
$
dbUser
user_id
-- user <- lift $ dbUser user_id
-- case user of
-- --Left err -> failure $ msg err
-- Left err -> error "fail"
-- Right u -> pure u
-- | Inner function to fetch the user from DB.
dbUser
::
Int
->
Cmd
err
(
Either
String
UserLight
)
dbUser
user_id
=
do
users
<-
getUsersWithId
user_id
case
users
of
[]
->
pure
$
Left
"User not found"
(
user
:
_
)
->
pure
$
Right
user
-- | Main GraphQL "app".
app
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
)
...
...
src/Gargantext/API/GraphQL/User.hs
0 → 100644
View file @
b947678a
{-# LANGUAGE DeriveAnyClass #-}
module
Gargantext.API.GraphQL.User
where
import
Data.Either
(
Either
(
..
))
import
Data.Maybe
(
fromMaybe
)
import
Data.Morpheus.Types
(
GQLType
,
ResolverQ
,
liftEither
)
import
Gargantext.API.Prelude
(
GargM
,
GargError
)
import
Gargantext.Database.Prelude
(
Cmd
,
HasConnectionPool
,
HasConfig
)
import
Gargantext.Database.Query.Table.User
(
getUsersWithId
)
import
Gargantext.Database.Schema.User
(
UserLight
)
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
qualified
Prelude
as
Prelude
-- | Arguments to the "user" query.
data
UserArgs
=
UserArgs
{
user_id
::
Int
,
includeHyperdata
::
Maybe
Bool
}
deriving
(
Generic
,
GQLType
)
-- | Function to resolve user from a query.
resolveUsers
::
(
HasConnectionPool
env
,
HasConfig
env
)
=>
UserArgs
->
ResolverQ
e
(
GargM
env
GargError
)
[
UserLight
]
resolveUsers
UserArgs
{
user_id
,
includeHyperdata
}
=
do
let
_hyp
=
fromMaybe
False
includeHyperdata
liftEither
$
dbUsers
user_id
-- user <- lift $ dbUser user_id
-- case user of
-- --Left err -> failure $ msg err
-- Left err -> error "fail"
-- Right u -> pure u
-- | Inner function to fetch the user from DB.
dbUsers
::
Int
->
Cmd
err
(
Either
Prelude
.
String
[
UserLight
])
dbUsers
user_id
=
do
users
<-
getUsersWithId
user_id
pure
$
Right
users
src/Gargantext/Database/Query/Table/User.hs
View file @
b947678a
...
...
@@ -107,7 +107,6 @@ getUsersWithId i = map toUserLight <$> runOpaQuery (selectUsersLightWithId i)
returnA
-<
row
queryUserTable
::
Query
UserRead
queryUserTable
=
selectTable
userTable
...
...
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