arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

outEdges and inEdges not working #802

Closed robross0606 closed 7 months ago

robross0606 commented 7 months ago

edgeCollection.outEdges() and edgeCollection.inEdges() no longer appear to be functional after upgrading from 7.8.0 to 8.6.0. Making a call such as await edgeCollection.outEdges('notLinks/test1') results in this error stack:

    TypeError: Cannot read properties of undefined (reading 'allowDirtyRead')
      at Collection._edges (node_modules/src/collection.ts:3914:13)
      at Collection.outEdges (node_modules/src/collection.ts:3934:17)
      at Object.outEdges (src/__tests__/arango-service.test.js:506:39)

I've reviewed the migration guide and looked at the latest API documentation, but don't see anything listed that should impact this.

robross0606 commented 7 months ago

The problem is definitely on collection.ts.

    _edges(selector, options, direction) {
        const { allowDirtyRead = undefined } = options;
        return this._db.request({
            path: `/_api/edges/${encodeURIComponent(this._name)}`,
            allowDirtyRead,
            qs: {
                direction,
                vertex: (0, documents_1._documentHandle)(selector, this._name, false),
            },
        });
    }
    edges(vertex, options) {
        return this._edges(vertex, options);
    }
    inEdges(vertex, options) {
        return this._edges(vertex, options, "in");
    }
    outEdges(vertex, options) {
        return this._edges(vertex, options, "out");
    }

None of these functions has a default for options so it breaks _edges because options is undefined. You cannot destructure something from undefined even if you have a default. This would break if options == undefined:

 const { allowDirtyRead = undefined } = options;

So this works:

await edgeCollection.outEdges('notLinks/test1', {})

But this doesn't:

await edgeCollection.outEdges('notLinks/test1')
pluma4345 commented 7 months ago

Good catch. The argument should be optional given that none of the options are required.