@@ -14,6 +14,7 @@ import {
1414 getFetchNodesByIdQuery ,
1515 getFetchDirectNeighboursOfNodeQuery ,
1616 getFetchNodeRelationshipsQuery ,
17+ getFetchEdgesByIdQuery ,
1718} from './utils'
1819import {
1920 EDGE_COLORS ,
@@ -56,7 +57,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
5657 let nodeIds = new Set ( parsedResponse . nodes . map ( n => n . id ) )
5758 let edgeIds = new Set ( parsedResponse . edges . map ( e => e . id ) )
5859
59- if ( nodeIds . size === 0 && parsedResponse . nodeIds . length === 0 ) {
60+ if ( nodeIds . size === 0 && parsedResponse . nodeIds . size === 0 ) {
6061 return < div className = "responseInfo" > No data to visualize. Switch to Text view to see raw information.</ div >
6162 }
6263
@@ -87,18 +88,29 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
8788 let newNodeLabels : { [ key : string ] : number } = nodeLabels
8889 let newEdgeTypes : { [ key : string ] : number } = edgeTypes
8990
90- if ( parsedResponse . nodeIds . length > 0 ) {
91+ if ( parsedResponse . hasNamedPathItem && parsedResponse . npNodeIds . length > 0 ) {
9192 try {
9293 /* 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 ] ) )
9595 if ( Array . isArray ( resp ) && ( resp . length >= 1 || resp [ 0 ] . status === 'success' ) ) {
9696 const parsedData = responseParser ( resp [ 0 ] . response )
9797 parsedData . nodes . forEach ( n => {
9898 nodeIds . add ( n . id )
9999 n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
100100 } )
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+ } )
102114
103115 newGraphData = {
104116 ...newGraphData ,
@@ -111,7 +123,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
111123 nodes : parsedData . nodes ,
112124 relationships : parsedData
113125 . 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 ) )
115127 . map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
116128 }
117129 } ]
@@ -124,7 +136,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
124136
125137 try {
126138 /* Fetch neighbours automatically */
127- const resp = await executeRedisCommand ( getFetchNodeRelationshipsQuery ( props . graphKey , [ ...nodeIds ] , [ ...nodeIds ] ) )
139+ const resp = await executeRedisCommand ( getFetchNodeRelationshipsQuery ( props . graphKey , [ ...nodeIds ] , [ ...nodeIds ] , [ ... edgeIds ] ) )
128140
129141 if ( Array . isArray ( resp ) && ( resp . length >= 1 || resp [ 0 ] . status === 'success' ) ) {
130142 const parsedData = responseParser ( resp [ 0 ] . response )
@@ -134,8 +146,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
134146 } )
135147 const filteredEdges = parsedData
136148 . 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 ) )
138151 . map ( e => {
152+ edgeIds . add ( e . id )
139153 newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 || 1 )
140154 return ( { ...e , startNode : e . source , endNode : e . target , fetchedAutomatically : true } )
141155 } )
@@ -200,7 +214,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
200214 n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
201215 } )
202216 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+ } )
204221
205222 graphd3 . updateWithGraphData ( {
206223 results : [ {
0 commit comments