You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return a Node.js ReadableStream set in Object mode. The stream emits a distinct `data` event per query result returned by Gremlin Server.
163
+
Return an RxJS `Observable` of results.
165
164
166
-
Internally, a 1-level flatten is performed on all raw protocol messages returned. If you do not wish this behavior and prefer handling raw protocol messages with batched results, prefer using `client.messageStream()`.
167
-
168
-
The order in which results are returned is guaranteed, allowing you to effectively use `order` steps and the like in your Gremlin traversal.
169
-
170
-
The stream emits an `end` event when the client receives the last `statusCode: 299` message returned by Gremlin Server.
165
+
Internally, a 1-level flatten is performed on all protocol messages returned.
171
166
172
167
```javascript
173
-
constquery=client.stream('g.V()');
174
-
175
-
// If playing with classic TinkerPop graph, will emit 6 data events
176
-
query.on('data', (result) => {
177
-
// Handle first vertex
178
-
console.log(result);
179
-
});
168
+
constquery$=client.observable('g.V()');
180
169
181
-
query.on('end', () => {
182
-
console.log('All results fetched');
183
-
});
170
+
query$.subscribe(
171
+
(vertex) =>console.log(vertex), // will log 6 times,
172
+
(err) =>console.error(err),
173
+
() =>console.log('Done!')
174
+
);
184
175
```
185
176
186
-
This allows you to effectively `.pipe()` the stream to any other Node.js WritableStream/TransformStream.
Although a public method, this is recommended for advanced usages only.
195
-
196
-
```javascript
197
-
constclient=Gremlin.createClient();
198
-
199
-
conststream=client.messageStream('g.V()');
200
-
201
-
// Will emit 3 events with a resultIterationBatchSize set to 2 and classic graph defined in gremlin-server.yaml
202
-
stream.on('data', (message) => {
203
-
console.log(message.result); // Array of 2 vertices
204
-
});
205
-
```
179
+
A lower level method that returns an `Observable` of raw protocol messages return by Gremlin Server.
180
+
Recommended for advanced usages/troubleshooting.
206
181
207
182
### Adding bound parameters to your scripts
208
183
209
184
For better performance and security concerns (script injection), you must send bound parameters (`bindings`) with your scripts.
210
185
211
-
`client.execute()`, `client.stream()` and `client.messageStream()` share the same function signature: `(script, bindings, querySettings)`.
186
+
`client.execute()`, `client.observable()` and `client.messageObservable()` share the same function signature: `(script, bindings, querySettings)`.
212
187
213
188
Notes/Gotchas:
214
189
- Any bindings set to `undefined` will be automatically escaped with `null` values (first-level only) in order to generate a valid JSON string sent to Gremlin Server.
Basically, all you have to do is provide an Object as third parameter to any `client.stream()`, `client.execute()` or `client.streamMessage()` methods.
229
+
Basically, all you have to do is provide an Object as third parameter to any `client.observable()`, `client.execute()` or `client.messageObservable()` methods.
255
230
256
231
Because we're not sending any bound parameters (`bindings`) in this example, notice how the second argument **must** be set to `null` so the low level message object is not mistaken with bound arguments.
0 commit comments