{"record":{"id":"31a51e65d798724d","repo":"hasura/graphql-engine","slug":"expected-a-non-null-value-but-received-null","errorCode":null,"errorMessage":"Expected a non-null value but received null","messagePattern":"Expected a non-null value but received null","errorType":"validation","errorClass":"TypecheckError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/helpers/typecheck.rs","lineNumber":23,"sourceCode":"use crate::types::error::ShouldBeAnError;\nuse crate::{Qualified, QualifiedBaseType, QualifiedTypeName, QualifiedTypeReference};\nuse open_dds::flags::Flag;\nuse open_dds::types::{CustomTypeName, FieldName};\nuse thiserror::Error;\n\n#[derive(Error, Debug, PartialEq)]\n/// Errors that can occur when typechecking a value\npub enum TypecheckError {\n    #[error(\"Expected a value of type {expected:} but got value {actual:}\")]\n    ScalarTypeMismatch {\n        expected: open_dds::types::InbuiltType,\n        actual: serde_json::Value,\n    },\n    #[error(\"Error in array item: {inner_error:}\")]\n    ArrayItemMismatch { inner_error: Box<TypecheckError> },\n    #[error(\"Expected an array but instead got value {value:}\")]\n    NonArrayValue { value: serde_json::Value },\n    #[error(\"Expected a non-null value but received null\")]\n    NullInNonNullableColumn,\n}\n\n#[derive(Error, Debug, PartialEq)]\n/// Issues that can occur when typechecking a value against an object type\npub enum TypecheckIssue {\n    #[error(\"Expected an object value of type {expected:} but got value {actual:}\")]\n    ObjectTypeMismatch {\n        expected: Qualified<CustomTypeName>,\n        actual: serde_json::Value,\n    },\n\n    #[error(\"Typecheck failed for field {field_name:} in object type {object_type:}: {error:}\")]\n    ObjectTypeField {\n        field_name: FieldName,\n        object_type: Qualified<CustomTypeName>,\n        error: TypecheckError,\n    },","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/helpers/typecheck.rs#L5-L41","documentation":"TypecheckError variant raised when a null JSON value is typechecked against a non-nullable type. It signals that the metadata explicitly contains null where the declared type disallows it (distinct from a missing key, which is handled elsewhere).","triggerScenarios":"Writing default: null or an explicit null element/field in metadata for a non-nullable argument, field, or array element (e.g. [Int!] contains a null item).","commonSituations":"Explicit nulls left over from templated/generated metadata, optional fields converted to non-optional without cleaning nulls, nulls inside arrays typed as non-null element lists.","solutions":["Remove the explicit null from the metadata","Make the target type nullable if null is a legitimate value","For arrays, ensure element type is nullable ([Int!]) before allowing null items"],"exampleFix":"// before\nfield:\n  type: Int!\n  default: null\n\n// after\nfield:\n  type: Int!\n  default: 0","handlingStrategy":"validation","validationCode":"fn reject_null_in_non_nullable(v: &serde_json::Value, nullable: bool) -> Result<(), String> {\n    if !nullable && v.is_null() {\n        Err(\"null value in non-nullable position\".into())\n    } else {\n        Ok(())\n    }\n}","typeGuard":null,"tryCatchPattern":"if let TypecheckError::NullInNonNullableColumn = err {\n    eprintln!(\"remove the explicit null or make the type nullable\");\n}","preventionTips":["Never write default: null explicitly; omit the key instead","Audit generated metadata for stray nulls","Make element types nullable ([Int!]) before allowing null items"],"tags":["metadata","typecheck","null","nullable"],"backgroundTag":"null-value-in-non-nullable-field","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}