17
17
* You should have received a copy of the GNU General Public License
18
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
*/
20
- import neo4j from 'neo4j-driver'
20
+ import neo4j , { QueryResult } from 'neo4j-driver'
21
21
import Rx from 'rxjs'
22
22
23
23
import {
@@ -46,6 +46,7 @@ import {
46
46
47
47
const NAME = 'cypher'
48
48
export const CYPHER_REQUEST = `${ NAME } /REQUEST`
49
+ export const ROUTED_CYPHER_READ_REQUEST = `${ NAME } /ROUTED_READ_REQUEST`
49
50
export const ROUTED_CYPHER_WRITE_REQUEST = `${ NAME } /ROUTED_WRITE_REQUEST`
50
51
export const AD_HOC_CYPHER_REQUEST = `${ NAME } /AD_HOC_REQUEST`
51
52
export const CLUSTER_CYPHER_REQUEST = `${ NAME } /CLUSTER_REQUEST`
@@ -113,6 +114,22 @@ const callClusterMember = async (connection: any, action: any) => {
113
114
} )
114
115
} )
115
116
}
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
+ }
116
133
117
134
// Epics
118
135
export const cypherRequestEpic = ( some$ : any ) =>
@@ -135,7 +152,20 @@ export const cypherRequestEpic = (some$: any) =>
135
152
} ) )
136
153
} )
137
154
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 ) =>
139
169
some$ . ofType ( ROUTED_CYPHER_WRITE_REQUEST ) . mergeMap ( ( action : any ) => {
140
170
if ( ! action . $$responseChannel ) return Rx . Observable . of ( null )
141
171
@@ -148,17 +178,8 @@ export const routedCypherRequestEpic = (some$: any) =>
148
178
useDb : action . useDb
149
179
}
150
180
)
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 )
162
183
} )
163
184
164
185
export const adHocCypherRequestEpic = ( some$ : any , store : any ) =>
0 commit comments