# Querying in Data Connectors

When building a Data Connector, you have access to a simplified version of the Graph Query Language via the IQuery interface exposed in the Curiosity.Library. This allows you to perform checks against the existing graph data during ingestion (e.g., to link new data to existing nodes).

# Available Methods

The Curiosity.Library.IQuery interface supports the following operations:

# Starting Points

  • StartAt(string nodeType): Start with all nodes of a type.
  • StartAt(Node node): Start with a specific node.
  • StartAt(Node[] nodes): Start with a set of nodes.

# Filtering

  • OfType(string nodeType): Filter by type.
  • OfTypes(string[] nodeTypes): Filter by multiple types.
  • ExceptType(string nodeType): Exclude a type.
  • ExceptTypes(string[] nodeTypes): Exclude multiple types.
  • IsRelatedTo(string nodeType): Keep nodes related to a type.
  • IsRelatedTo(Node node, bool assumeBidirectionalEdges): Keep nodes related to a specific node.
  • IsNotRelatedTo(string nodeType): Exclude nodes related to a type.
  • IsNotRelatedTo(Node node, bool assumeBidirectionalEdges): Exclude nodes related to a specific node.

# Traversal

  • Out(): Traverse to all connected nodes.
  • Out(string nodeType): Traverse to nodes of a specific type.
  • Out(string nodeType, string edgeType): Traverse via a specific edge.
  • OutMany(int levels, ...): Traverse multiple levels deep.
  • Similar(string index, int count, float tolerance): Find similar nodes.

# Output

  • Emit(string key): Output the current nodes under a key.
  • EmitCount(string key): Output the count of nodes.
  • EmitWithEdges(string key): Output nodes with their edges.

# Sorting & Paging

  • SortByTimestamp(bool oldestFirst)
  • SortByLastUpdated(bool newestFirst)
  • SortByConnectivity(bool mostConnectedFirst)
  • Skip(int count)
  • Take(int count)

# Examples

# Checking for Existing Parent Nodes

When ingesting a document, you might want to check if its parent folder already exists in the graph.

public void Process(Document doc, IQuery query)
{
    // Check if the folder exists
    query.StartAt(Node.FromKey("Folder", doc.FolderName))
         .Emit("ExistingFolder");
}

# Linking to Authors

Finding an author node to link a book to.

query.StartAt(Node.FromKey("Author", "John Doe"))
     .Take(1)
     .Emit("AuthorNode");