Skip to content

Commit ea0029f

Browse files
committed
Fix #740
1 parent 6807a07 commit ea0029f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ This driver uses semantic versioning:
3838

3939
- Added support for `fillBlockCache` query option
4040

41+
- Added support for passing `Graph` objects in AQL queries [#740](https://github.com/arangodb/arangojs/issues/740)
42+
43+
This also adds the `isArangoGraph` helper function for type checking.
44+
4145
- Added User Management API [#664](https://github.com/arangodb/arangojs/issues/664)
4246

4347
This implements the endpoints of the

src/aql.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @packageDocumentation
1212
*/
1313
import { ArangoCollection, isArangoCollection } from "./collection";
14+
import { Graph, isArangoGraph } from "./graph";
1415
import { isArangoView, View } from "./view";
1516

1617
/**
@@ -70,6 +71,7 @@ export interface AqlLiteral {
7071
export type AqlValue =
7172
| ArangoCollection
7273
| View
74+
| Graph
7375
| GeneratedAqlQuery
7476
| AqlLiteral
7577
| string
@@ -241,7 +243,11 @@ export function aql(
241243
const index = bindValues.indexOf(rawValue);
242244
const isKnown = index !== -1;
243245
let name = `value${isKnown ? index : bindValues.length}`;
244-
if (isArangoCollection(rawValue) || isArangoView(rawValue)) {
246+
if (
247+
isArangoCollection(rawValue) ||
248+
isArangoGraph(rawValue) ||
249+
isArangoView(rawValue)
250+
) {
245251
name = `@${name}`;
246252
value = rawValue.name;
247253
}

src/graph.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ import {
3535
import { isArangoError } from "./error";
3636
import { DOCUMENT_NOT_FOUND, GRAPH_NOT_FOUND } from "./lib/codes";
3737

38+
/**
39+
* Indicates whether the given value represents a {@link Graph}.
40+
*
41+
* @param graph - A value that might be a Graph.
42+
*/
43+
export function isArangoGraph(graph: any): graph is Graph {
44+
return Boolean(graph && graph.isArangoGraph);
45+
}
46+
3847
/**
3948
* @internal
4049
* @hidden
@@ -1200,6 +1209,15 @@ export class Graph {
12001209
this._db = db;
12011210
}
12021211

1212+
/**
1213+
* @internal
1214+
*
1215+
* Indicates that this object represents an ArangoDB Graph.
1216+
*/
1217+
get isArangoGraph(): true {
1218+
return true;
1219+
}
1220+
12031221
/**
12041222
* Name of the graph.
12051223
*/

0 commit comments

Comments
 (0)