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'
2121import Rx from 'rxjs'
2222
2323import {
@@ -46,6 +46,7 @@ import {
4646
4747const NAME = 'cypher'
4848export const CYPHER_REQUEST = `${ NAME } /REQUEST`
49+ export const ROUTED_CYPHER_READ_REQUEST = `${ NAME } /ROUTED_READ_REQUEST`
4950export const ROUTED_CYPHER_WRITE_REQUEST = `${ NAME } /ROUTED_WRITE_REQUEST`
5051export const AD_HOC_CYPHER_REQUEST = `${ NAME } /AD_HOC_REQUEST`
5152export 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
118135export 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
164185export const adHocCypherRequestEpic = ( some$ : any , store : any ) =>
0 commit comments