Skip to content

Commit 560cb6b

Browse files
daveajrussellOskarDamkjaer
authored andcommitted
update viz component to use routed requests
1 parent f3504d4 commit 560cb6b

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/browser/modules/Stream/CypherFrame/VisualizationView/VisualizationView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
3838
import { deepEquals } from 'neo4j-arc/common'
3939
import { GlobalState } from 'shared/globalState'
40-
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
40+
import { ROUTED_CYPHER_READ_REQUEST } from 'shared/modules/cypher/cypherDuck'
4141
import * as grassActions from 'shared/modules/grass/grassDuck'
4242
import {
4343
getMaxFieldItems,
@@ -197,7 +197,7 @@ LIMIT ${maxNewNeighbours}`
197197
return new Promise((resolve, reject) => {
198198
this.props.bus &&
199199
this.props.bus.self(
200-
CYPHER_REQUEST,
200+
ROUTED_CYPHER_READ_REQUEST,
201201
{ query: query, queryType: NEO4J_BROWSER_USER_ACTION_QUERY },
202202
(response: any) => {
203203
if (!response.success) {
@@ -242,7 +242,7 @@ LIMIT ${maxNewNeighbours}`
242242
return new Promise(resolve => {
243243
this.props.bus &&
244244
this.props.bus.self(
245-
CYPHER_REQUEST,
245+
ROUTED_CYPHER_READ_REQUEST,
246246
{
247247
query,
248248
params: { existingNodeIds, newNodeIds },

src/shared/modules/cypher/cypherDuck.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
import neo4j from 'neo4j-driver'
20+
import neo4j, { QueryResult } from 'neo4j-driver'
2121
import Rx from 'rxjs'
2222

2323
import {
@@ -46,6 +46,7 @@ import {
4646

4747
const NAME = 'cypher'
4848
export const CYPHER_REQUEST = `${NAME}/REQUEST`
49+
export const ROUTED_CYPHER_READ_REQUEST = `${NAME}/ROUTED_READ_REQUEST`
4950
export const ROUTED_CYPHER_WRITE_REQUEST = `${NAME}/ROUTED_WRITE_REQUEST`
5051
export const AD_HOC_CYPHER_REQUEST = `${NAME}/AD_HOC_REQUEST`
5152
export const CLUSTER_CYPHER_REQUEST = `${NAME}/CLUSTER_REQUEST`
@@ -113,6 +114,22 @@ const callClusterMember = async (connection: any, action: any) => {
113114
})
114115
})
115116
}
117+
const routedCypherQueryResultResolver = async (
118+
action: any,
119+
promise: Promise<QueryResult>
120+
) => {
121+
return promise
122+
.then((result: any) => ({
123+
type: action.$$responseChannel,
124+
success: true,
125+
result
126+
}))
127+
.catch((error: any) => ({
128+
type: action.$$responseChannel,
129+
success: false,
130+
error
131+
}))
132+
}
116133

117134
// Epics
118135
export const cypherRequestEpic = (some$: any) =>
@@ -135,7 +152,20 @@ export const cypherRequestEpic = (some$: any) =>
135152
}))
136153
})
137154

138-
export const routedCypherRequestEpic = (some$: any) =>
155+
export const routedCypherReadRequestEpic = (some$: any) =>
156+
some$.ofType(ROUTED_CYPHER_READ_REQUEST).mergeMap((action: any) => {
157+
if (!action.$$responseChannel) return Rx.Observable.of(null)
158+
159+
const promise = bolt.routedReadTransaction(action.query, action.params, {
160+
...getUserTxMetadata(action.queryType || null),
161+
cancelable: true,
162+
useDb: action.useDb
163+
})
164+
165+
return routedCypherQueryResultResolver(action, promise)
166+
})
167+
168+
export const routedCypherWriteRequestEpic = (some$: any) =>
139169
some$.ofType(ROUTED_CYPHER_WRITE_REQUEST).mergeMap((action: any) => {
140170
if (!action.$$responseChannel) return Rx.Observable.of(null)
141171

@@ -148,17 +178,8 @@ export const routedCypherRequestEpic = (some$: any) =>
148178
useDb: action.useDb
149179
}
150180
)
151-
return promise
152-
.then((result: any) => ({
153-
type: action.$$responseChannel,
154-
success: true,
155-
result
156-
}))
157-
.catch((error: any) => ({
158-
type: action.$$responseChannel,
159-
success: false,
160-
error
161-
}))
181+
182+
return routedCypherQueryResultResolver(action, promise)
162183
})
163184

164185
export const adHocCypherRequestEpic = (some$: any, store: any) =>

src/shared/rootEpic.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ import {
5353
clusterCypherRequestEpic,
5454
cypherRequestEpic,
5555
handleForcePasswordChangeEpic,
56-
routedCypherRequestEpic
56+
routedCypherReadRequestEpic,
57+
routedCypherWriteRequestEpic
5758
} from './modules/cypher/cypherDuck'
5859
import {
5960
clearMetaOnDisconnectEpic,
@@ -122,7 +123,8 @@ export default combineEpics(
122123
injectDiscoveryEpic,
123124
populateEditorFromUrlEpic,
124125
adHocCypherRequestEpic,
125-
routedCypherRequestEpic,
126+
routedCypherReadRequestEpic,
127+
routedCypherWriteRequestEpic,
126128
cypherRequestEpic,
127129
clusterCypherRequestEpic,
128130
clearLocalstorageEpic,

0 commit comments

Comments
 (0)