arangodb / arangojs

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

Invalid edge can be created although the vertex does not exist ? #565

Closed Arun-KumarH closed 6 years ago

Arun-KumarH commented 6 years ago

Hello,

I have created a vertex collection named 'vertices' and created an edge named ('vertice_to_vertice_edge') between the 'vertices' collection. I inserted two vertices (with keys 1 and 2) and created and edge between them.

// Valid Edge created await createEdge('vertice_to_vertice_edge', {some: 'edgeData1'}, 'vertices/1', 'vertices/2');

// Invalid Edge should not have been created await createEdge('vertice_to_vertice_edge', {some: 'edgeData2'}, 'vertices/3', 'vertices/4');

If I try to create one more edge between vertex keys (3 and 4) the edge still gets created although the vertices 3 and 4 does not exist ? Is this the expected behaviour ? (I can post the code snippet if needed to reproduce).

Thank you.

async function createEdge(edgeCollectionName, data, fromID, toID) {
  if (_.isNil(edgeCollectionName)) {
    throw new Error('missing edge collection name');
  }
  if (_.isNil(data)) {
    data = {};
  }

  try {
    const collection = graph.edgeCollection(edgeCollectionName);
    collection.save(data, fromID, toID);
  } catch(ex) {
    console.log('Ex caught creating edge:', ex.message);
  }
}
pluma commented 6 years ago

Since arangojs just uses the HTTP API, this sounds like a bug in ArangoDB, not arangojs. The code you have posted here seems to correctly use the GraphEdgeCollection, which uses the graph API to save documents.

Can you please create an issue at https://github.com/arangodb/arangodb/issues/new and reference this one in it?

Simran-B commented 6 years ago

@pluma Does arangojs wrap the Gharial API, or does it use the document API for this?

pluma commented 6 years ago

@Simran-B As I said, it uses the graph API (i.e. gharial).

Simran-B commented 6 years ago

Thanks for the clarification. I wasn't sure if there's another graph API that would allow you to create edges, because we do have other graph-related endpoints, but this one here is for querying only and points you to the normal document endpoints for CRUD: https://docs.arangodb.com/devel/HTTP/Edge/WorkingWithEdges.html

pluma commented 6 years ago

@Simran-B That is why I clarified it. Regular EdgeCollection uses the regular edge API. But the code example uses graph.edgeCollection which returns a GraphEdgeCollection.

This is the route GraphEdgeCollection#save uses:

/_api/gharial/${this.graph.name}/edge/${this.name}
pluma commented 6 years ago

To clarify: I'm assuming graph is indeed a Graph, not a Database.

Arun-KumarH commented 6 years ago

Works with DB version 3.3.9.