!CHAPTER Fluent AQL Interface
This chapter describes a fluent interface to query your graph.
The philosophy of this interface is to select a group of starting elements (vertices or edges) at first and from there on explore the graph with your query by selecting connected elements.
As an example you can start with a set of vertices, select their direct neighbors and finally their outgoing edges.
The result of this query will be the set of outgoing edges.
For each part of the query it is possible to further refine the resulting set of elements by giving examples for them.
!SECTION Starting Points
This section describes the entry points for the fluent interface.
The philosophy of this module is to start with a specific subset of vertices or edges and from there on iterate over the graph.
Therefore you get exactly this two entry points:
* Select a set of edges
* Select a set of vertices
!SUBSECTION Edges
!SUBSECTION Vertices
!SECTION Working with the query cursor
The fluent query object handles cursor creation and maintenance for you.
A cursor will be created as soon as you request the first result.
If you are unhappy with the current result and want to refine it further you can execute a further step in the query which cleans up the cursor for you.
In this interface you get the complete functionality available for general AQL cursors directly on your query.
The cursor functionality is described in this section.
!SUBSECTION ToArray
!SUBSECTION HasNext
!SUBSECTION Next
!SUBSECTION Count
!SECTION Fluent queries
After the selection of the entry point you can now query your graph in
a fluent way, meaning each of the functions on your query returns the query again.
Hence it is possible to chain arbitrary many executions one after the other.
In this section all available query statements are described.
!SUBSECTION Edges
`graph-query.edges(examples)`
*Select all edges for the vertices selected before.*
Creates an AQL statement to select all edges for each of the vertices selected
in the step before.
This will include *inbound* as well as *outbound* edges.
The resulting set of edges can be filtered by defining one or more *examples*.
*examples* can have the following values:
* Empty, there is no matching executed all edges are valid.
* A string, only the edge having this value as it's id is returned.
* An example object, defining a set of attributes.
Only edges having these attributes are matched.
* A list containing example objects and/or strings.
All edges matching at least one of the elements in the list are returned.
@EXAMPLES
To request unfiltered edges:
```
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("social");
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
arangosh> query.edges().toArray();
[
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
},
{
"_id" : "relation/31932839",
"_rev" : "31932839",
"_key" : "31932839",
"_from" : "female/30491047",
"_to" : "male/31080871",
"type" : "friend"
},
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
},
{
"_id" : "relation/32326055",
"_rev" : "32326055",
"_key" : "32326055",
"_from" : "male/30884263",
"_to" : "female/31277479",
"type" : "friend"
}
]
arangosh> examples.dropGraph("social");
undefined
```
To request filtered edges by a single example:
```
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("social");
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
arangosh> query.edges({type: "married"}).toArray();
[
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
},
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
}
]
arangosh> examples.dropGraph("social");
undefined
```
To request filtered edges by multiple examples:
```
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("social");
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
arangosh> query.edges([{type: "married"}, {type: "friend"}]).toArray();
[
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
},
{
"_id" : "relation/31932839",
"_rev" : "31932839",
"_key" : "31932839",
"_from" : "female/30491047",
"_to" : "male/31080871",
"type" : "friend"
},
{
"_id" : "relation/31670695",
"_rev" : "31670695",
"_key" : "31670695",
"_from" : "female/30491047",
"_to" : "male/30884263",
"type" : "married"
},
{
"_id" : "relation/32326055",
"_rev" : "32326055",
"_key" : "32326055",
"_from" : "male/30884263",
"_to" : "female/31277479",
"type" : "friend"
}
]
arangosh> examples.dropGraph("social");
undefined
```
!SUBSECTION OutEdges
!SUBSECTION InEdges
!SUBSECTION Vertices
!SUBSECTION FromVertices
!SUBSECTION ToVertices
!SUBSECTION Neighbors
!SUBSECTION Restrict
!SUBSECTION Filter
!SUBSECTION Path