Skip to content

Keyword

query

Back to Index
query
<edge>[(<columns>)]
[filter '<filter>']
[orderBy 'field asc|desc']
[navigate]

The query keyword provides access to the Graph using a simple query definition syntax.

Query Definition

A query is made up of a root navigation. Each navigation can have multiple nested navigations that will be performed in a single query and returned as nested records.

Each navigation can be filtered and sorted, as well as specify zero or more fields.

Filtering is done using the filter keyword and takes a text as input. Similary, ordering is done using the orderBy keyword. The texts can be interpolated texts that are evaluated at runtime. The format follows Hantera’s standard graph filter/order by values.

Nested navigations are done using the navigate keyword. A simple example fetching orders and order lines could look like this:

from
query orders(orderNumber)
orderBy 'orderNumber desc'
navigate orderLines(productNumber, quantity)
orderBy 'orderLineNumber'

Query Result

The query result type is constructed dynamically based on the query definition, similar to how the Graph API works. This means that definitions are checked at compile time, and an invalid query will not be attempted.

When working with queries in Hantera Development Studio it’s important that your session is connected to a Hantera backend in order for the graph metadata to be available. Querying custom sets will not be allowed by the compiler unless the backend can verify the existence of said sets.

Error Handling

While a query definition can be almost be completely checked at compile time, filter and orderBy allows dynamic string interpolation and can therefor lead to runtime errors. When an error occurs, a QueryError record is returned.

Paging

Paging is currently not supported. Queries only return the first 100 hits for any navigation.

Examples

From the Cookbook:

from {
get = (args) =>
// Query for orders ordered by latest creation timestamp
let orderQuery =
query orders(orderNumber)
orderBy 'createdAt desc'
// Extract order number from query result
let orderNumber = orderQuery match
QueryError |> 'Error'
|>
orderQuery
select r => r.orderNumber
first // first returns first orderNumber or nothing
from return (
orderNumber match
nothing |> 'No orders'
|> orderNumber
)
}
Back to Index