{"record":{"id":"9409607d412a3b50","repo":"hasura/graphql-engine","slug":"the-type-of-the-order-by-expression-order-by-expr","errorCode":null,"errorMessage":"The type of the order by expression {order_by_expression_name} referenced in field {field_name} does not match the field type. Order by expression type: {order_by_expression_type}; field type: {field_type}. ","messagePattern":"The type of the order by expression (.+?) referenced in field (.+?) does not match the field type\\. Order by expression type: (.+?); field type: (.+?)\\. ","errorType":"validation","errorClass":"OrderByExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/order_by_expressions/error.rs","lineNumber":57,"sourceCode":"    #[error(\n        \"Invalid orderable field {field_name}. Exactly one of `enable_order_by_directions` or `order_by_expression_name` must be specified.\"\n    )]\n    InvalidOrderByExpressionOrderableField { field_name: FieldName },\n    #[error(\n        \"The order by expression {order_by_expression_name} referenced in field {field_name} has not been defined\"\n    )]\n    UnknownOrderByExpressionNameInOrderableField {\n        order_by_expression_name: OrderByExpressionName,\n        field_name: FieldName,\n    },\n    #[error(\n        \"The order by expression {order_by_expression_name} referenced in orderable relationship {relationship_name} has not been defined\"\n    )]\n    UnknownOrderByExpressionNameInOrderableRelationship {\n        order_by_expression_name: OrderByExpressionName,\n        relationship_name: RelationshipName,\n    },\n    #[error(\n        \"The type of the order by expression {order_by_expression_name} referenced in field {field_name} does not match the field type. Order by expression type: {order_by_expression_type}; field type: {field_type}. \"\n    )]\n    OrderableFieldTypeError {\n        order_by_expression_name: OrderByExpressionName,\n        order_by_expression_type: TypeName,\n        field_type: QualifiedBaseType,\n        field_name: FieldName,\n    },\n    #[error(\"{0}\")]\n    GraphqlConfigError(#[from] graphql_config::GraphqlConfigError),\n    #[error(\"{message}\")]\n    UnsupportedFeature { message: String },\n}\n\n#[derive(Debug, thiserror::Error)]\n#[allow(clippy::enum_variant_names)]\npub enum OrderableRelationshipError {\n    #[error(","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/order_by_expressions/error.rs#L39-L75","documentation":"The type produced by the order-by expression does not match the type of the field that references it. The message prints both the expression's type and the field's (qualified base) type; they must agree for ordering to type-check.","triggerScenarios":"An order_by_expression returns e.g. a computed String while the field is typed as a timestamp scalar, or the expression was written against a different column/type than the field it is attached to.","commonSituations":"Expressions returning a coerced/cast value differing from the column type; changing a field's type without updating its expression; connector type mapping differences making resolved types diverge.","solutions":["Align the expression's output type with the field's declared type (cast inside the expression or adjust the expression)","Re-check the field's type mapping if it recently changed","If the expression intentionally orders differently, give the field a matching type or use a dedicated expression/field pair"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure expression output type equals the field's type\nconst exprType = resolveExpressionType(orderByExpressions[name]);\nif (!typeNameEquals(exprType, fieldBaseType(field.type))) throw new Error(`Type mismatch for order-by expression ${name}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write expressions against the same column they order","Re-validate expressions after changing a field's declared type"],"tags":["hasura","metadata","order-by","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}