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
d07faa3e
Commit
d07faa3e
authored
Oct 21, 2021
by
Alp Mestanogullari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support nested resolving for user hyperdata
parent
b19e86ef
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
39 deletions
+28
-39
GraphQL.hs
src/Gargantext/API/GraphQL.hs
+6
-7
User.hs
src/Gargantext/API/GraphQL/User.hs
+22
-32
No files found.
src/Gargantext/API/GraphQL.hs
View file @
d07faa3e
...
@@ -77,12 +77,12 @@ import Servant
...
@@ -77,12 +77,12 @@ import Servant
-- | Represents possible GraphQL queries.
-- | Represents possible GraphQL queries.
data
Query
m
data
Query
m
=
Query
=
Query
{
users
::
UserArgs
->
m
[
User
]
{
users
::
UserArgs
->
m
[
User
m
]
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
-- | Possible GraphQL Events, i.e. here we describe how we will
-- | Possible GraphQL Events, i.e. here we describe how we will
-- manipulate the data.
-- manipulate the data.
type
EVENT
=
Event
Channel
Contet
type
EVENT
m
=
Event
Channel
(
Contet
m
)
-- | Channels are possible actions to call when manipulating the data.
-- | Channels are possible actions to call when manipulating the data.
data
Channel
data
Channel
...
@@ -91,15 +91,14 @@ data Channel
...
@@ -91,15 +91,14 @@ data Channel
deriving
(
Eq
,
Show
,
Generic
,
Hashable
)
deriving
(
Eq
,
Show
,
Generic
,
Hashable
)
-- | This type describes what data we will operate on.
-- | This type describes what data we will operate on.
data
Contet
data
Contet
m
=
UserContet
[
User
]
=
UserContet
[
User
m
]
-- | The main GraphQL resolver: how queries, mutations and
-- | The main GraphQL resolver: how queries, mutations and
-- subscriptions are handled.
-- subscriptions are handled.
rootResolver
rootResolver
::
(
HasConnectionPool
env
,
HasConfig
env
)
::
(
HasConnectionPool
env
,
HasConfig
env
)
=>
RootResolver
(
GargM
env
GargError
)
EVENT
Query
Undefined
Undefined
=>
RootResolver
(
GargM
env
GargError
)
e
Query
Undefined
Undefined
rootResolver
=
rootResolver
=
RootResolver
RootResolver
{
queryResolver
=
Query
{
users
=
resolveUsers
}
{
queryResolver
=
Query
{
users
=
resolveUsers
}
...
@@ -109,7 +108,7 @@ rootResolver =
...
@@ -109,7 +108,7 @@ rootResolver =
-- | Main GraphQL "app".
-- | Main GraphQL "app".
app
app
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
)
::
(
Typeable
env
,
HasConnectionPool
env
,
HasConfig
env
)
=>
App
EVENT
(
GargM
env
GargError
)
=>
App
(
EVENT
(
GargM
env
GargError
))
(
GargM
env
GargError
)
app
=
deriveApp
rootResolver
app
=
deriveApp
rootResolver
----------------------------------------------
----------------------------------------------
...
...
src/Gargantext/API/GraphQL/User.hs
View file @
d07faa3e
...
@@ -2,28 +2,27 @@
...
@@ -2,28 +2,27 @@
module
Gargantext.API.GraphQL.User
where
module
Gargantext.API.GraphQL.User
where
import
Data.
Either
(
Either
(
..
)
)
import
Data.
Maybe
(
listToMaybe
)
import
Data.Morpheus.Types
import
Data.Morpheus.Types
(
GQLType
(
GQLType
,
Resolver
Q
,
Resolver
,
QUERY
,
lift
Either
,
lift
)
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.API.Prelude
(
GargM
,
GargError
)
import
Gargantext.API.Prelude
(
GargM
,
GargError
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataUser
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataUser
(
..
))
import
Gargantext.Database.Prelude
(
Cmd
,
HasConnectionPool
,
HasConfig
)
import
Gargantext.Database.Prelude
(
HasConnectionPool
,
HasConfig
)
import
Gargantext.Database.Query.Table.User
(
getUsersWithId
,
getUserHyperdata
)
import
Gargantext.Database.Query.Table.User
(
getUsersWithId
,
getUserHyperdata
)
import
Gargantext.Database.Schema.User
(
UserLight
(
..
))
import
Gargantext.Database.Schema.User
(
UserLight
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
qualified
Prelude
as
Prelude
data
User
=
User
data
User
m
=
User
{
u_email
::
Text
{
u_email
::
Text
,
u_hyperdata
::
Maybe
HyperdataUser
,
u_hyperdata
::
m
(
Maybe
HyperdataUser
)
,
u_id
::
Int
,
u_id
::
Int
,
u_username
::
Text
}
,
u_username
::
Text
}
deriving
(
Show
,
Generic
,
GQLType
)
deriving
(
Generic
,
GQLType
)
-- | Arguments to the "user" query.
-- | Arguments to the "user" query.
data
UserArgs
data
UserArgs
...
@@ -31,38 +30,29 @@ data UserArgs
...
@@ -31,38 +30,29 @@ data UserArgs
{
user_id
::
Int
{
user_id
::
Int
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
type
GqlM
e
env
=
Resolver
QUERY
e
(
GargM
env
GargError
)
-- | Function to resolve user from a query.
-- | Function to resolve user from a query.
resolveUsers
resolveUsers
::
(
HasConnectionPool
env
,
HasConfig
env
)
::
(
HasConnectionPool
env
,
HasConfig
env
)
=>
UserArgs
->
ResolverQ
e
(
GargM
env
GargError
)
[
User
]
=>
UserArgs
->
GqlM
e
env
[
User
(
GqlM
e
env
)]
resolveUsers
UserArgs
{
user_id
}
=
do
resolveUsers
UserArgs
{
user_id
}
=
dbUsers
user_id
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.
-- | Inner function to fetch the user from DB.
dbUsers
::
Int
->
Cmd
err
(
Either
Prelude
.
String
[
User
])
dbUsers
dbUsers
user_id
=
do
::
(
HasConnectionPool
env
,
HasConfig
env
)
users
<-
getUsersWithId
user_id
=>
Int
->
GqlM
e
env
([
User
(
GqlM
e
env
)])
-- users' <- if includeHyperdata
dbUsers
user_id
=
lift
(
map
toUser
<$>
getUsersWithId
user_id
)
-- then mapM injectHyperdata (toUser <$> users)
-- else (pure $ toUser <$> users)
users'
<-
mapM
injectHyperdata
$
toUser
<$>
users
pure
$
Right
users'
toUser
::
UserLight
->
User
toUser
::
(
HasConnectionPool
env
,
HasConfig
env
)
=>
UserLight
->
User
(
GqlM
e
env
)
toUser
(
UserLight
{
..
})
=
User
{
u_email
=
userLight_email
toUser
(
UserLight
{
..
})
=
User
{
u_email
=
userLight_email
,
u_hyperdata
=
Nothing
,
u_hyperdata
=
resolveHyperdata
userLight_id
,
u_id
=
userLight_id
,
u_id
=
userLight_id
,
u_username
=
userLight_username
}
,
u_username
=
userLight_username
}
injectHyperdata
::
User
->
Cmd
err
User
resolveHyperdata
injectHyperdata
user
@
(
User
{
..
})
=
do
::
(
HasConnectionPool
env
,
HasConfig
env
)
hyperdata
<-
getUserHyperdata
u_id
=>
Int
->
GqlM
e
env
(
Maybe
HyperdataUser
)
case
hyperdata
of
resolveHyperdata
userid
=
lift
(
listToMaybe
<$>
getUserHyperdata
userid
)
[]
->
pure
$
user
(
h
:
_
)
->
pure
$
User
{
u_hyperdata
=
Just
h
,
..
}
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