@@ -14,6 +14,7 @@ import {
14
14
getFetchNodesByIdQuery ,
15
15
getFetchDirectNeighboursOfNodeQuery ,
16
16
getFetchNodeRelationshipsQuery ,
17
+ getFetchEdgesByIdQuery ,
17
18
} from './utils'
18
19
import {
19
20
EDGE_COLORS ,
@@ -56,7 +57,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
56
57
let nodeIds = new Set ( parsedResponse . nodes . map ( n => n . id ) )
57
58
let edgeIds = new Set ( parsedResponse . edges . map ( e => e . id ) )
58
59
59
- if ( nodeIds . size === 0 && parsedResponse . nodeIds . length === 0 ) {
60
+ if ( nodeIds . size === 0 && parsedResponse . nodeIds . size === 0 ) {
60
61
return < div className = "responseInfo" > No data to visualize. Switch to Text view to see raw information.</ div >
61
62
}
62
63
@@ -87,18 +88,29 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
87
88
let newNodeLabels : { [ key : string ] : number } = nodeLabels
88
89
let newEdgeTypes : { [ key : string ] : number } = edgeTypes
89
90
90
- if ( parsedResponse . nodeIds . length > 0 ) {
91
+ if ( parsedResponse . hasNamedPathItem && parsedResponse . npNodeIds . length > 0 ) {
91
92
try {
92
93
/* Fetch named path nodes */
93
- const resp = await executeRedisCommand ( getFetchNodesByIdQuery ( props . graphKey , [ ...parsedResponse . nodeIds ] ) )
94
-
94
+ let resp = await executeRedisCommand ( getFetchNodesByIdQuery ( props . graphKey , [ ...parsedResponse . npNodeIds ] ) )
95
95
if ( Array . isArray ( resp ) && ( resp . length >= 1 || resp [ 0 ] . status === 'success' ) ) {
96
96
const parsedData = responseParser ( resp [ 0 ] . response )
97
97
parsedData . nodes . forEach ( n => {
98
98
nodeIds . add ( n . id )
99
99
n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
100
100
} )
101
- parsedData . edges . forEach ( e => newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1 )
101
+
102
+ resp = await executeRedisCommand ( getFetchEdgesByIdQuery ( props . graphKey , [ ...parsedResponse . npEdgeIds ] ) )
103
+ if ( Array . isArray ( resp ) && ( resp . length >= 1 || resp [ 0 ] . status === 'success' ) ) {
104
+ const edgeParsedData = responseParser ( resp [ 0 ] . response )
105
+ parsedData . edges = [ ...edgeParsedData . edges ]
106
+ parsedData . edgeIds = edgeParsedData . edgeIds
107
+ }
108
+
109
+ parsedData . edges = parsedData . edges . filter ( e => ! edgeIds . has ( e . id ) )
110
+ parsedData . edges . forEach ( e => {
111
+ edgeIds . add ( e . id )
112
+ newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1
113
+ } )
102
114
103
115
newGraphData = {
104
116
...newGraphData ,
@@ -111,7 +123,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
111
123
nodes : parsedData . nodes ,
112
124
relationships : parsedData
113
125
. edges
114
- . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) && ! edgeIds . has ( e . id ) )
126
+ . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) )
115
127
. map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
116
128
}
117
129
} ]
@@ -124,7 +136,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
124
136
125
137
try {
126
138
/* Fetch neighbours automatically */
127
- const resp = await executeRedisCommand ( getFetchNodeRelationshipsQuery ( props . graphKey , [ ...nodeIds ] , [ ...nodeIds ] ) )
139
+ const resp = await executeRedisCommand ( getFetchNodeRelationshipsQuery ( props . graphKey , [ ...nodeIds ] , [ ...nodeIds ] , [ ... edgeIds ] ) )
128
140
129
141
if ( Array . isArray ( resp ) && ( resp . length >= 1 || resp [ 0 ] . status === 'success' ) ) {
130
142
const parsedData = responseParser ( resp [ 0 ] . response )
@@ -134,8 +146,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
134
146
} )
135
147
const filteredEdges = parsedData
136
148
. edges
137
- . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) && ! edgeIds . has ( e . id ) )
149
+ . filter ( e => ! edgeIds . has ( e . id ) )
150
+ . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) )
138
151
. map ( e => {
152
+ edgeIds . add ( e . id )
139
153
newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 || 1 )
140
154
return ( { ...e , startNode : e . source , endNode : e . target , fetchedAutomatically : true } )
141
155
} )
@@ -200,7 +214,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
200
214
n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
201
215
} )
202
216
const filteredEdges = parsedData . edges . filter ( e => ! edgeIds . has ( e . id ) ) . map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
203
- filteredEdges . forEach ( e => newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1 )
217
+ filteredEdges . forEach ( e => {
218
+ edgeIds . add ( e . id )
219
+ newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1
220
+ } )
204
221
205
222
graphd3 . updateWithGraphData ( {
206
223
results : [ {
0 commit comments