#
Graph Query Language
The Curiosity Graph Query Language is a fluent interface used to interact with the graph database. It is primarily accessed via the Q() helper method in Custom Endpoints or through the IQuery interface in Data Connectors (with a reduced feature set).
#
Overview
The query language follows a pipeline approach:
- Start: Define the starting set of nodes (e.g., all nodes of a type, a specific search, or a list of UIDs).
- Filter: Narrow down the set based on properties, relationships, or permissions.
- Traverse: Move from the current set of nodes to related nodes (e.g., "get authors of these books").
- Project/Sort: Define what data to return and in what order.
- Execute: Materialize the results (e.g., as a list, count, or JSON).
#
Starting Points
Every query must start by defining an initial set of nodes.
#
Examples
// Start with all "Project" nodes
var projects = Q().StartAt("Project");
// Start with a specific search
var results = Q().StartSearch("Email", "Subject", Search("urgent"));
#
Filtering
Refine the current set of nodes.
#
Examples
// Filter active users
Q().StartAt("User")
.WhereString("Status", "Active");
// Filter documents created in the last 7 days
Q().StartAt("Document")
.WhereTimestamp(DateTime.Now.AddDays(-7), DateTime.Now, true);
#
Graph Traversal
Move from the current nodes to their neighbors.
#
Examples
// Get all authors of books matching "Graph DB"
Q().StartSearch("Book", "Title", Search("Graph DB"))
.Out("Author", "WrittenBy");
// Get friends of friends
Q().StartAt(currentUserUid)
.OutMany(2, new[] { "Person" }, new[] { "FriendOf" });
#
Output and Projection
Define what extra information to include in the result.
#
Examples
// Return books with their author edges
Q().StartAt("Book")
.EmitWithEdges(null, false, "WrittenBy");
#
Sorting and Pagination
Control the order and number of results.
#
Examples
// Get top 10 most recent documents
Q().StartAt("Document")
.SortByTimestamp(false)
.Take(10);
#
Execution
Materialize the query execution into a result.
#
Examples
// Get count of users
int count = Q().StartAt("User").Count();
// Get list of high-priority tasks
var tasks = Q().StartAt("Task")
.WhereString("Priority", "High")
.ToList();