Skip to content

Source

Every query starts with from(), which specifies the node kind to query and assigns an alias for referencing it throughout the query.

const results = await store
.query()
.from("Person", "p") // Start from Person nodes, alias as "p"
.select((ctx) => ctx.p)
.execute();
.from(kind, alias, options?)
ParameterTypeDescription
kindstringThe node kind to query (must exist in your graph definition)
aliasstringA unique identifier for referencing this node in the query
options.includeSubClassesbooleanInclude nodes of subclass kinds (default: false)

The alias is used throughout the query to reference the node:

const results = await store
.query()
.from("Person", "person")
.whereNode("person", (p) => p.status.eq("active")) // Reference in filter
.orderBy("person", "name", "asc") // Reference in ordering
.select((ctx) => ({
name: ctx.person.name, // Reference in selection
email: ctx.person.email,
}))
.execute();

Aliases must be unique within a query. TypeScript enforces this at compile time:

store
.query()
.from("Person", "p")
.traverse("worksAt", "e")
.to("Company", "p") // TypeScript error: alias "p" already in use

If your ontology defines subclass relationships, you can query a parent kind and include all subclasses:

// Graph definition with subclass relationships:
// subClassOf(Podcast, Media)
// subClassOf(Article, Media)
// subClassOf(Video, Media)
// Query only exact Media nodes (default behavior)
const exactMedia = await store
.query()
.from("Media", "m")
.select((ctx) => ctx.m)
.execute();
// Query Media and all subclasses
const allMedia = await store
.query()
.from("Media", "m", { includeSubClasses: true })
.select((ctx) => ({
kind: ctx.m.kind, // "Media" | "Podcast" | "Article" | "Video"
title: ctx.m.title,
}))
.execute();

When includeSubClasses: true:

  • Results include nodes of the specified kind AND all subclass kinds
  • The kind field in results reflects the actual node kind
  • All properties common to the parent kind are accessible

from() returns a QueryBuilder that provides access to all query methods:

  • Filter - Reduce results with whereNode()
  • Traverse - Navigate to related nodes
  • Shape - Define output with select()