mirror of https://gitee.com/bigwinds/arangodb
461 lines
9.7 KiB
Plaintext
461 lines
9.7 KiB
Plaintext
!CHAPTER Manage your graphs
|
|
|
|
The graph module provides functions dealing with graph structures.
|
|
|
|
!SECTION First Steps with Graphs
|
|
|
|
A Graph consists of *vertices* and *edges*. Edges are stored as documents in *edge
|
|
collections*. A vertex can be a document of a *document collection* or of an edge
|
|
collection (so edges can be used as vertices). Which collections are used within
|
|
a graph is defined via *edge definitions*. A graph can contain more than one edge
|
|
definition, at least one is needed.
|
|
|
|
!SECTION List all graphs
|
|
|
|
`GET /system/gharial/` *(lists all graphs)*
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_info -->
|
|
|
|
Lists all graph names stored in this database.
|
|
<br />
|
|
@EXAMPLES
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_http_examples -->
|
|
|
|
```
|
|
unix> curl --dump - http://localhost:8529/system/gharial
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"graphs" : [
|
|
"routeplanner",
|
|
"social"
|
|
]
|
|
}
|
|
```
|
|
|
|
!SECTION Create a graph
|
|
|
|
`POST /system/gharial/` *(create a graph)*
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_create_info -->
|
|
|
|
The creation of a graph requires the name of the graph and a definition of its edges.
|
|
<br />
|
|
@EXAMPLES
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_create_http_examples -->
|
|
|
|
```
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/system/gharial
|
|
{"name":"myGraph","edgeDefinitions":[{"collection":"edges","from":["startVertices"],"to":["endVertices"]}]}
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 201,
|
|
"graph" : {
|
|
"name" : "myGraph",
|
|
"edgeDefinitions" : [
|
|
{
|
|
"collection" : "edges",
|
|
"from" : [
|
|
"startVertices"
|
|
],
|
|
"to" : [
|
|
"endVertices"
|
|
]
|
|
}
|
|
],
|
|
"orphanCollections" : [ ]
|
|
}
|
|
}
|
|
```
|
|
|
|
!SECTION Drop a graph
|
|
|
|
`DELETE /system/gharial/graph-name`*(drop a graph)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
|
|
The name of the graph.
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_drop_info -->
|
|
|
|
Removes a graph from the collection *\_graphs*.
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_drop_http_examples -->
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/system/gharial/social
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
|
|
```
|
|
|
|
!SECTION List all vertex collections in the graph
|
|
|
|
`GET /system/gharial/graph-name/vertex`*(lists all vertex collections)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_vertex_info -->
|
|
|
|
Lists all vertex collections within this graph.
|
|
|
|
@EXAMPLES
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_vertex_http_examples -->
|
|
|
|
```
|
|
unix> curl --dump - http://localhost:8529/system/gharial/social/vertex
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"collections" : [
|
|
"female",
|
|
"male"
|
|
]
|
|
}
|
|
|
|
```
|
|
|
|
!SECTION Add a new vertex collection to the graph
|
|
|
|
`POST /system/gharial/graph-name/vertex`*(add a new vertex collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertex_collection_add_info -->
|
|
|
|
Adds a vertex collection to the set of collections of the graph. If the
|
|
collection does not exist, it will be created.
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertex_collection_add_http_examples -->
|
|
|
|
```
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/system/gharial/social/vertex
|
|
{"collection":"otherVertices"}
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 201,
|
|
"graph" : {
|
|
"name" : "social",
|
|
"edgeDefinitions" : [
|
|
{
|
|
"collection" : "relation",
|
|
"from" : [
|
|
"female",
|
|
"male"
|
|
],
|
|
"to" : [
|
|
"female",
|
|
"male"
|
|
]
|
|
}
|
|
],
|
|
"orphanCollections" : [
|
|
"otherVertices"
|
|
]
|
|
}
|
|
}
|
|
|
|
```
|
|
|
|
!SECTION Remove a vertex collection form the graph
|
|
|
|
`DELETE /system/gharial/graph-name/vertex/collection-name`*(remove a vertex collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
The name of the graph.
|
|
|
|
`collection-name (string, required)`
|
|
The name of the vertex collection.
|
|
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertex_collection_remove_info -->
|
|
|
|
Removes a vertex collection from the graph and deletes the collection, if it is not used in any other graph.
|
|
|
|
@EXAMPLES
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertex_collection_remove_http_examples -->
|
|
|
|
<br />
|
|
You can remove vertex collections that are not used in any edge collection:
|
|
<br />
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/system/gharial/social/vertex/otherVertices
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"graph" : {
|
|
"name" : "social",
|
|
"edgeDefinitions" : [
|
|
{
|
|
"collection" : "relation",
|
|
"from" : [
|
|
"female",
|
|
"male"
|
|
],
|
|
"to" : [
|
|
"female",
|
|
"male"
|
|
]
|
|
}
|
|
],
|
|
"orphanCollections" : [ ]
|
|
}
|
|
}
|
|
|
|
```
|
|
<br />
|
|
You cannot remove vertex collections that are used in edge collections:
|
|
<br />
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/system/gharial/social/vertex/male
|
|
|
|
HTTP/1.1 400 Bad Request
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : "The collection is not found or part of an edge definition."
|
|
}
|
|
|
|
```
|
|
<br />
|
|
|
|
!SECTION List all edge definitions in the graph
|
|
|
|
`GET /system/gharial/graph-name/edge` *(lists all edge definitions)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_edge_info -->
|
|
|
|
Lists all edge collections within this graph.
|
|
|
|
@EXAMPLES
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_list_edge_http_examples -->
|
|
|
|
```
|
|
unix> curl --dump - http://localhost:8529/system/gharial/social/edge
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"collections" : [
|
|
"relation"
|
|
]
|
|
}
|
|
|
|
```
|
|
|
|
!SECTION Add a new edge definition to the graph
|
|
|
|
`POST /system/gharial/graph-name/edge` *(add a new edge definition)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_add_info -->
|
|
|
|
Adds an additional edge definition to the graph.
|
|
This edge definition has to contain a *collection* a list of each *from* and *to* vertex collections.
|
|
A edge definition can only be added if this definition is either not used in any other graph, or it is used with exactly the same definition.
|
|
It is not possible to store a definition "e" from "v1" to "v2" in the one graph, and "e" from "v2" to "v1" in the other graph.
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_add_http_examples -->
|
|
|
|
```
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/system/gharial/social/edge
|
|
{"collection":"lives_in","from":["female","male"],"to":["city"]}
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 201,
|
|
"graph" : {
|
|
"name" : "social",
|
|
"edgeDefinitions" : [
|
|
{
|
|
"collection" : "relation",
|
|
"from" : [
|
|
"female",
|
|
"male"
|
|
],
|
|
"to" : [
|
|
"female",
|
|
"male"
|
|
]
|
|
},
|
|
{
|
|
"collection" : "lives_in",
|
|
"from" : [
|
|
"female",
|
|
"male"
|
|
],
|
|
"to" : [
|
|
"city"
|
|
]
|
|
}
|
|
],
|
|
"orphanCollections" : [ ]
|
|
}
|
|
}
|
|
```
|
|
|
|
!SECTION Modify an edge definition
|
|
|
|
`DELETE /system/gharial/graph-name/edge/definition-name` *(remove a vertex collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
The name of the graph.
|
|
|
|
`definition-name (string, required)`
|
|
The name of the edge collection used in the definition.
|
|
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_modify_info -->
|
|
|
|
Change one specific edge definition.
|
|
This will modify all occurrences of this definition in all graphs known to your database.
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_modify_http_examples -->
|
|
|
|
```
|
|
unix> curl -X PUT --data-binary @- --dump - http://localhost:8529/system/gharial/social/edge/relation
|
|
{"collection":"relation","from":["female","male","animal"],"to":["female","male","animal"]}
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"graph" : {
|
|
"name" : "social",
|
|
"edgeDefinitions" : [
|
|
{
|
|
"collection" : "relation",
|
|
"from" : [
|
|
"female",
|
|
"male",
|
|
"animal"
|
|
],
|
|
"to" : [
|
|
"female",
|
|
"male",
|
|
"animal"
|
|
]
|
|
}
|
|
],
|
|
"orphanCollections" : [ ]
|
|
}
|
|
}
|
|
|
|
```
|
|
|
|
!SECTION Remove an edge definition form the graph
|
|
|
|
`DELETE /system/gharial/graph-name/edge/definition-name`*(remove a vertex collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`graph-name (string, required)`
|
|
The name of the graph.
|
|
|
|
`definition-name (string, required)`
|
|
The name of the edge collection used in the definition.
|
|
|
|
|
|
!SUBSECTION Description
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_remove_info -->
|
|
|
|
Remove one edge definition from the graph.
|
|
This will only remove the edge collection, the vertex collections remain untouched and can still be used in your queries.
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edge_definition_remove_http_examples -->
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/system/gharial/social/edge/relation
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error" : false,
|
|
"code" : 200,
|
|
"graph" : {
|
|
"name" : "social",
|
|
"edgeDefinitions" : [ ],
|
|
"orphanCollections" : [ ]
|
|
}
|
|
}
|
|
|
|
```
|