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
bc9a0853
Commit
bc9a0853
authored
Apr 28, 2022
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GQL] Node parent IDs in tree
parent
f860b55e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
TreeFirstLevel.hs
src/Gargantext/API/GraphQL/TreeFirstLevel.hs
+15
-10
No files found.
src/Gargantext/API/GraphQL/TreeFirstLevel.hs
View file @
bc9a0853
...
@@ -31,6 +31,7 @@ data TreeNode = TreeNode
...
@@ -31,6 +31,7 @@ data TreeNode = TreeNode
name
::
Text
name
::
Text
,
id
::
Int
,
id
::
Int
,
node_type
::
NodeType
,
node_type
::
NodeType
,
parent_id
::
Maybe
Int
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
data
TreeFirstLevel
m
=
TreeFirstLevel
data
TreeFirstLevel
m
=
TreeFirstLevel
...
@@ -42,34 +43,37 @@ data TreeFirstLevel m = TreeFirstLevel
...
@@ -42,34 +43,37 @@ data TreeFirstLevel m = TreeFirstLevel
type
GqlM
e
env
=
Resolver
QUERY
e
(
GargM
env
GargError
)
type
GqlM
e
env
=
Resolver
QUERY
e
(
GargM
env
GargError
)
type
ParentId
=
Maybe
NodeId
resolveTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
TreeArgs
->
GqlM
e
env
(
TreeFirstLevel
(
GqlM
e
env
))
resolveTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
TreeArgs
->
GqlM
e
env
(
TreeFirstLevel
(
GqlM
e
env
))
resolveTree
TreeArgs
{
root_id
}
=
dbTree
root_id
resolveTree
TreeArgs
{
root_id
}
=
dbTree
root_id
dbTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
Int
->
GqlM
e
env
(
TreeFirstLevel
(
GqlM
e
env
))
dbTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
Int
->
GqlM
e
env
(
TreeFirstLevel
(
GqlM
e
env
))
dbTree
root_id
=
do
dbTree
root_id
=
do
t
<-
lift
$
T
.
tree
T
.
TreeFirstLevel
(
NodeId
root_id
)
allNodeTypes
let
rId
=
NodeId
root_id
t
<-
lift
$
T
.
tree
T
.
TreeFirstLevel
rId
allNodeTypes
n
<-
lift
$
getNode
$
NodeId
root_id
n
<-
lift
$
getNode
$
NodeId
root_id
let
pId
=
toParentId
n
let
pId
=
toParentId
n
pure
$
toTree
pId
t
pure
$
toTree
rId
pId
t
where
where
toParentId
N
.
Node
{
_node_parent_id
}
=
_node_parent_id
toParentId
N
.
Node
{
_node_parent_id
}
=
_node_parent_id
toTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
Maybe
Node
Id
->
Tree
NodeTree
->
TreeFirstLevel
(
GqlM
e
env
)
toTree
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
NodeId
->
Parent
Id
->
Tree
NodeTree
->
TreeFirstLevel
(
GqlM
e
env
)
toTree
pId
TreeN
{
_tn_node
,
_tn_children
}
=
TreeFirstLevel
toTree
rId
pId
TreeN
{
_tn_node
,
_tn_children
}
=
TreeFirstLevel
{
parent
=
resolveParent
pId
{
parent
=
resolveParent
pId
,
root
=
toTreeNode
_tn_node
,
root
=
toTreeNode
pId
_tn_node
,
children
=
map
childrenToTreeNodes
_tn_children
,
children
=
map
childrenToTreeNodes
$
zip
_tn_children
$
repeat
rId
}
}
toTreeNode
::
NodeTree
->
TreeNode
toTreeNode
::
ParentId
->
NodeTree
->
TreeNode
toTreeNode
NodeTree
{
_nt_name
,
_nt_id
,
_nt_type
}
=
TreeNode
{
name
=
_nt_name
,
id
=
id2int
_nt_id
,
node_type
=
_nt_type
}
toTreeNode
pId
NodeTree
{
_nt_name
,
_nt_id
,
_nt_type
}
=
TreeNode
{
name
=
_nt_name
,
id
=
id2int
_nt_id
,
node_type
=
_nt_type
,
parent_id
=
id2int
<$>
pId
}
where
where
id2int
::
NodeId
->
Int
id2int
::
NodeId
->
Int
id2int
(
NodeId
n
)
=
n
id2int
(
NodeId
n
)
=
n
childrenToTreeNodes
::
Tree
NodeTree
->
TreeNode
childrenToTreeNodes
::
(
Tree
NodeTree
,
NodeId
)
->
TreeNode
childrenToTreeNodes
TreeN
{
_tn_node
}
=
toTreeNode
_tn_node
childrenToTreeNodes
(
TreeN
{
_tn_node
},
rId
)
=
toTreeNode
(
Just
rId
)
_tn_node
resolveParent
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
Maybe
NodeId
->
GqlM
e
env
(
Maybe
TreeNode
)
resolveParent
::
(
HasConnectionPool
env
,
HasConfig
env
,
HasMail
env
)
=>
Maybe
NodeId
->
GqlM
e
env
(
Maybe
TreeNode
)
resolveParent
(
Just
pId
)
=
do
resolveParent
(
Just
pId
)
=
do
...
@@ -82,4 +86,5 @@ nodeToTreeNode :: NN.Node json -> TreeNode
...
@@ -82,4 +86,5 @@ nodeToTreeNode :: NN.Node json -> TreeNode
nodeToTreeNode
N
.
Node
{
..
}
=
TreeNode
{
id
=
NN
.
unNodeId
_node_id
nodeToTreeNode
N
.
Node
{
..
}
=
TreeNode
{
id
=
NN
.
unNodeId
_node_id
,
name
=
_node_name
,
name
=
_node_name
,
node_type
=
fromNodeTypeId
_node_typename
,
node_type
=
fromNodeTypeId
_node_typename
,
parent_id
=
NN
.
unNodeId
<$>
_node_parent_id
}
}
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