OrderBy Inputs
OrderByInput types for sorting GraphQL query results
Audience: Programmer
OrderByInput types define how query results should be sorted in the pyck GraphQL API. They provide a standardized way to order results by various fields in ascending or descending order.
Common Structure
All OrderByInput types follow a consistent pattern:
input EntityOrder {
field: EntityOrderField
direction: OrderDirection! = ASC
jsonPath: String
jsonType: JSONType
}Where:
field: An enum specifying which field to sort by (optional when using JSONB ordering)direction: EitherASC(ascending) orDESC(descending)jsonPath: Dot-notation path into a JSONB column (e.g., "meta.weight") for ordering by nested JSON valuesjsonType: Type casting for the extracted JSONB value (NUMBER,STRING, orBOOLEAN)
Usage Examples
Basic Sorting
Sort inventory items by name in ascending order:
Descending Order
Sort picking orders by creation date (newest first):
JavaScript Example
Available Order Types
The following Order input types are available in pyck:
CustomerOrder
Customers
TENANT_ID, CREATED_AT, CREATED_BY
DataTypeOrder
Data type definitions
NAME, SLUG, CREATED_AT
EventOrder
Event definitions
NAME, TOPIC, CREATED_AT
FileOrder
File attachments
NAME, SIZE, CREATED_AT
GroupOrder
User groups
NAME, CREATED_AT
InventoryCollectionOrder
Inventory collections
HANDLER, CREATED_AT
InventoryItemOrder
Inventory items
SKU, CREATED_AT
InventoryItemSetOrder
Item sets
SKU, CREATED_AT
ItemMovementOrder
Item movements
CREATED_AT, EXECUTED_AT
KeyValueOrder
Key-value pairs
NAME, CREATED_AT
PickingOrderOrder
Picking orders
CUSTOMER_ID, CREATED_AT
PickingOrderItemOrder
Picking order items
SKU, QUANTITY, CREATED_AT
ReceivingInboundOrder
Receiving inbounds
ORDER_ID, SUPPLIER_ID, CREATED_AT
ReceivingInboundItemOrder
Inbound items
SKU, QUANTITY, CREATED_AT
RepositoryOrder
Repositories
NAME, TYPE, CREATED_AT
RepositoryMovementOrder
Repository movements
CREATED_AT, EXECUTED_AT
RoleOrder
User roles
NAME, CREATED_AT
StockOrder
Stock levels
CREATED_AT, QUANTITY
SupplierOrder
Suppliers
TENANT_ID, CREATED_AT
TenantOrder
Tenants
NAME, CREATED_AT
TransactionOrder
Transactions
TYPE, CREATED_AT
UserOrder
Users
USERNAME, EMAIL, CREATED_AT
WorkflowOrder
Workflows
NAME, ACTIVE, CREATED_AT
WorkflowSignalOrder
Workflow signals
EVENT_NAME, CREATED_AT
Order Field Enums
Each entity has its own OrderField enum defining sortable fields. Common fields include:
NAME- Entity nameCREATED_AT- Creation timestampUPDATED_AT- Last update timestampREFERENCE_ID- External reference identifierSKU- Stock keeping unitEMAIL- Email addressTYPE- Entity typeEXECUTED_AT- Execution timestamp
JSONB Column Ordering
All OrderByInput types support ordering by nested fields within JSONB columns (such as the data field on entities). This allows you to sort by custom attributes stored as JSON.
Structure
When ordering by JSONB fields, you must provide:
jsonPath: Dot-notation path to the nested field (e.g., "attributes.weight", "meta.priority")jsonType: The data type of the value for proper sorting (NUMBER,STRING, orBOOLEAN)direction: Sort direction (ASCorDESC)field: Can be omitted when using JSONB ordering
Example: Order Inventory Items by Weight
Example: Order by Nested String Field
Example: Order by Boolean Flag
JSONType Enum
The JSONType enum specifies how to cast the extracted JSONB value for sorting:
JSONB Ordering Notes
Type Casting: Always specify the correct
jsonTypeto ensure proper sorting behaviorMissing Fields: Items without the specified JSON path will be sorted as null values
Nested Paths: Use dot notation for deeply nested fields (e.g., "meta.shipping.weight")
Performance: JSONB ordering may be slower than ordering by indexed columns
Best Practices
Default Sorting: Consider providing a default sort order when none is specified
Performance: Be aware that sorting by non-indexed fields may impact query performance
JSONB Performance: JSONB ordering is more expensive than standard field ordering; use judiciously
Consistency: Use consistent sorting across related queries for better UX
Null Values: Understand how null values are sorted (typically first for ASC, last for DESC)
Type Safety: Always specify the correct
jsonTypewhen using JSONB ordering to avoid unexpected results
Combining with Pagination
OrderByInput works seamlessly with cursor-based pagination:
See Also
WhereInput Types for filtering
Pagination for cursor-based pagination
OrderDirection Enum for sort directions
Last updated
Was this helpful?
