#
Querying the Graph (Query)
The Query interface is a fluent API for constructing and executing queries against the Curiosity Graph Database. It allows you to select starting nodes, filter them, traverse relationships, and shape the final output.
You typically obtain a Query instance by calling Graph.Query() or G.Q().
#
Starting a Query
Every query must start with a selection of nodes.
// Start with all Person nodes
var q = Graph.Query().StartAt("Person");
// Start with a specific user
var q = Graph.Query().StartAt("User", "john@example.com");
// Start with search results
var q = Graph.Query().StartSearch("Document", "content", Search.Parse("project alpha"));
#
Accessing Properties
When you access nodes (e.g. inside a Where clause or when materializing results), you can use strongly-typed accessor methods.
Dictionary Access:
GetDictionary(key): Returns anIReadOnlyDictionaryAccessorfor nested objects.
// Accessing scalar
string name = node.GetString("name");
// Accessing list
var tags = node.GetStringList("tags");
// Accessing dictionary
var meta = node.GetDictionary("metadata");
string source = meta.GetString("source");
#
Filtering
Refine the set of nodes currently in the query pipeline.
// Filter by property (string optimized)
q.WhereString("status", "Active");
// General filter
q.Where(node => node.GetFloat("confidence") > 0.8f);
#
Traversing Relationships
Move from the current set of nodes to related nodes.
// Get friends of people
q.StartAt("Person").Out("Person", "Friend");
// Get friends of friends (2 hops)
q.StartAt("Person").OutMany(2, new[] { "Person" });
// Find people related to a specific Project
q.StartAt("Person").IsRelatedTo(projectUID);
#
Sorting and Paging
Order and limit the results.
// Top 10 most connected people
q.StartAt("Person")
.SortByConnectivity(mostConnectedFirst: true)
.Take(10);
#
Shaping Output
Control what data is returned in the final result.
#
Materializing Results
Execute the query and get the data.
// Iterate over results (Code/Endpoints)
foreach (var node in q.AsEnumerable())
{
Console.WriteLine(node.UID);
}
// Return JSON (Shell/Debugging)
return await q.ToJsonAsync();