Skip to content

Commit

Permalink
update viz component to use routed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
daveajrussell authored and OskarDamkjaer committed Aug 2, 2024
1 parent f3504d4 commit 560cb6b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
import { deepEquals } from 'neo4j-arc/common'
import { GlobalState } from 'shared/globalState'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { ROUTED_CYPHER_READ_REQUEST } from 'shared/modules/cypher/cypherDuck'
import * as grassActions from 'shared/modules/grass/grassDuck'
import {
getMaxFieldItems,
Expand Down Expand Up @@ -197,7 +197,7 @@ LIMIT ${maxNewNeighbours}`
return new Promise((resolve, reject) => {
this.props.bus &&
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_READ_REQUEST,
{ query: query, queryType: NEO4J_BROWSER_USER_ACTION_QUERY },
(response: any) => {
if (!response.success) {
Expand Down Expand Up @@ -242,7 +242,7 @@ LIMIT ${maxNewNeighbours}`
return new Promise(resolve => {
this.props.bus &&
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_READ_REQUEST,
{
query,
params: { existingNodeIds, newNodeIds },
Expand Down
47 changes: 34 additions & 13 deletions src/shared/modules/cypher/cypherDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import neo4j from 'neo4j-driver'
import neo4j, { QueryResult } from 'neo4j-driver'
import Rx from 'rxjs'

import {
Expand Down Expand Up @@ -46,6 +46,7 @@ import {

const NAME = 'cypher'
export const CYPHER_REQUEST = `${NAME}/REQUEST`
export const ROUTED_CYPHER_READ_REQUEST = `${NAME}/ROUTED_READ_REQUEST`
export const ROUTED_CYPHER_WRITE_REQUEST = `${NAME}/ROUTED_WRITE_REQUEST`
export const AD_HOC_CYPHER_REQUEST = `${NAME}/AD_HOC_REQUEST`
export const CLUSTER_CYPHER_REQUEST = `${NAME}/CLUSTER_REQUEST`
Expand Down Expand Up @@ -113,6 +114,22 @@ const callClusterMember = async (connection: any, action: any) => {
})
})
}
const routedCypherQueryResultResolver = async (
action: any,
promise: Promise<QueryResult>
) => {
return promise
.then((result: any) => ({
type: action.$$responseChannel,
success: true,
result
}))
.catch((error: any) => ({
type: action.$$responseChannel,
success: false,
error
}))
}

// Epics
export const cypherRequestEpic = (some$: any) =>
Expand All @@ -135,7 +152,20 @@ export const cypherRequestEpic = (some$: any) =>
}))
})

export const routedCypherRequestEpic = (some$: any) =>
export const routedCypherReadRequestEpic = (some$: any) =>
some$.ofType(ROUTED_CYPHER_READ_REQUEST).mergeMap((action: any) => {
if (!action.$$responseChannel) return Rx.Observable.of(null)

const promise = bolt.routedReadTransaction(action.query, action.params, {
...getUserTxMetadata(action.queryType || null),
cancelable: true,
useDb: action.useDb
})

return routedCypherQueryResultResolver(action, promise)
})

export const routedCypherWriteRequestEpic = (some$: any) =>
some$.ofType(ROUTED_CYPHER_WRITE_REQUEST).mergeMap((action: any) => {
if (!action.$$responseChannel) return Rx.Observable.of(null)

Expand All @@ -148,17 +178,8 @@ export const routedCypherRequestEpic = (some$: any) =>
useDb: action.useDb
}
)
return promise
.then((result: any) => ({
type: action.$$responseChannel,
success: true,
result
}))
.catch((error: any) => ({
type: action.$$responseChannel,
success: false,
error
}))

return routedCypherQueryResultResolver(action, promise)
})

export const adHocCypherRequestEpic = (some$: any, store: any) =>
Expand Down
6 changes: 4 additions & 2 deletions src/shared/rootEpic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import {
clusterCypherRequestEpic,
cypherRequestEpic,
handleForcePasswordChangeEpic,
routedCypherRequestEpic
routedCypherReadRequestEpic,
routedCypherWriteRequestEpic
} from './modules/cypher/cypherDuck'
import {
clearMetaOnDisconnectEpic,
Expand Down Expand Up @@ -122,7 +123,8 @@ export default combineEpics(
injectDiscoveryEpic,
populateEditorFromUrlEpic,
adHocCypherRequestEpic,
routedCypherRequestEpic,
routedCypherReadRequestEpic,
routedCypherWriteRequestEpic,
cypherRequestEpic,
clusterCypherRequestEpic,
clearLocalstorageEpic,
Expand Down

0 comments on commit 560cb6b

Please sign in to comment.