Skip to main content

Order Time Buckets

The orderTimeBuckets query provides time-series aggregation of orders, grouping them into configurable time intervals. It's designed for analytics dashboards, charts, and trend analysis.

Query Signature

query OrderTimeBuckets(
$organizationId: Int!
$interval: TimeBucketInterval!
$dateField: String!
$start: DateTime!
$end: DateTime!
$includeEmpty: Boolean
$includeSummary: Boolean
$filter: String
$search: String
) {
orderTimeBuckets(
organizationId: $organizationId
interval: $interval
dateField: $dateField
start: $start
end: $end
includeEmpty: $includeEmpty
filter: $filter
search: $search
) {
totalCount
buckets {
bucketStart
bucketEnd
count
summary {
totalWeight
totalPieces
totalQuantity
totalIncome
totalExpense
totalProfit
}
orders(take: 10, orderBy: "created desc") {
items {
orderId
trackingNumber
created
}
totalCount
}
}
}
}

Parameters

ParameterTypeRequiredDefaultDescription
organizationIdIntYesOrganization to query
intervalTimeBucketIntervalYesTime interval for bucketing
dateFieldStringYesDate field to group by
startDateTimeYesRange start (inclusive)
endDateTimeYesRange end (exclusive)
includeEmptyBooleanNotrueInclude buckets with zero orders
filterStringNoLucene filter applied to orders
searchStringNoFull-text search applied to orders

TimeBucketInterval

ValuePostgreSQL IntervalMax Buckets
Minutes55 minutes288
Minutes1515 minutes672
Minutes3030 minutes1,344
Hour11 hour744
Hours44 hours744
Day11 day366
Week17 days104
Month11 month60

If the date range × interval exceeds the maximum bucket count, the query returns an error with a suggestion to narrow the range or use a larger interval.

dateField

Supported values:

ValueDescription
createdOrder creation date
lastModifiedLast modification date
lastOrderStatusModifiedLast status change date
customValues.<key>Any JSONB custom value containing a date (e.g., customValues.ETA, customValues.pickupDate)

Custom value dates must match the pattern YYYY-MM-DD... and are cast to timestamp at query time.

Response Types

OrderTimeBucketsResult

FieldTypeDescription
totalCountIntNumber of buckets returned
buckets[OrderTimeBucket]Array of time buckets

OrderTimeBucket

FieldTypeDescription
bucketStartDateTimeBucket start time (UTC)
bucketEndDateTimeBucket end time (UTC)
countIntNumber of orders in this bucket
summaryOrderTimeBucketSummary?Aggregate summary (only populated when summary is selected)
ordersCollectionSegment<Order>Paginated orders within this bucket

OrderTimeBucketSummary

FieldTypeDescription
totalWeightDecimalSum of order weights
totalPiecesDecimalSum of pieces
totalQuantityDecimalSum of quantities
totalIncomeDecimalSum of income charges
totalExpenseDecimalSum of expense charges
totalProfitDecimalIncome minus expense
Performance

The summary fields are only computed when explicitly selected in the GraphQL query. If you only need counts, omit the summary selection to avoid the join to the vw_order_summary view.

Data Source

Summary data is sourced from the vw_order_summary database view, which pre-aggregates totals from orders, commodities, and charges. The view includes:

  • OrderId, OrganizationId, OrderStatusId, IsDraft
  • Created, LastModified, LastOrderStatusModified
  • CustomValues (JSONB)
  • TotalWeight, TotalPieces, TotalQuantity
  • TotalIncome, TotalExpense, TotalProfit

Examples

Daily order count for the last 30 days

query {
orderTimeBuckets(
organizationId: 1
interval: Day1
dateField: "created"
start: "2026-02-21T00:00:00Z"
end: "2026-03-23T00:00:00Z"
) {
totalCount
buckets {
bucketStart
count
}
}
}

Weekly revenue breakdown with filter

query {
orderTimeBuckets(
organizationId: 1
interval: Week1
dateField: "created"
start: "2026-01-01T00:00:00Z"
end: "2026-03-23T00:00:00Z"
filter: "orderStatus.name:Completed"
) {
buckets {
bucketStart
bucketEnd
count
summary {
totalIncome
totalExpense
totalProfit
}
}
}
}

Hourly analysis with drill-down to orders

query {
orderTimeBuckets(
organizationId: 1
interval: Hour1
dateField: "customValues.ETA"
start: "2026-03-22T00:00:00Z"
end: "2026-03-23T00:00:00Z"
) {
buckets {
bucketStart
count
orders(take: 5, orderBy: "created desc") {
items {
orderId
trackingNumber
customValues
}
totalCount
}
}
}
}