hasura/graphql-engine · error · TypecheckError

Expected an array but instead got value {value:}

Error message

Expected an array but instead got value {value:}

What it means

TypecheckError variant thrown when typechecking an array-typed value but the provided JSON value is not a JSON array (e.g. it is an object, string, or number). It includes the offending value so you can immediately see what was passed instead.

Source

Thrown at v3/crates/metadata-resolve/src/helpers/typecheck.rs:21

use crate::stages::object_types;
use crate::types::error::ShouldBeAnError;
use crate::{Qualified, QualifiedBaseType, QualifiedTypeName, QualifiedTypeReference};
use open_dds::flags::Flag;
use open_dds::types::{CustomTypeName, FieldName};
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
/// Errors that can occur when typechecking a value
pub enum TypecheckError {
    #[error("Expected a value of type {expected:} but got value {actual:}")]
    ScalarTypeMismatch {
        expected: open_dds::types::InbuiltType,
        actual: serde_json::Value,
    },
    #[error("Error in array item: {inner_error:}")]
    ArrayItemMismatch { inner_error: Box<TypecheckError> },
    #[error("Expected an array but instead got value {value:}")]
    NonArrayValue { value: serde_json::Value },
    #[error("Expected a non-null value but received null")]
    NullInNonNullableColumn,
}

#[derive(Error, Debug, PartialEq)]
/// Issues that can occur when typechecking a value against an object type
pub enum TypecheckIssue {
    #[error("Expected an object value of type {expected:} but got value {actual:}")]
    ObjectTypeMismatch {
        expected: Qualified<CustomTypeName>,
        actual: serde_json::Value,
    },

    #[error("Typecheck failed for field {field_name:} in object type {object_type:}: {error:}")]
    ObjectTypeField {
        field_name: FieldName,
        object_type: Qualified<CustomTypeName>,

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Wrap the value in an array: [value]
  2. Check YAML flow syntax so the value parses as a sequence (starts with '-')
  3. Confirm the declared type really is an array type and not a scalar

Example fix

// before
default: 5   # type: [Int!]

// after
default: [5]
Defensive patterns

Strategy: type-guard

Type guard

fn is_json_array(v: &serde_json::Value) -> bool {
    v.is_array()
}

Try / catch

if let TypecheckError::NonArrayValue { value } = err {
    eprintln!("expected an array, got {value}; wrap it in []");
}

Prevention

When it happens

Trigger: Supplying a scalar or object where the declared type is an array, e.g. default: 5 for an argument typed [Int!]!, or passing an object literal for a list input in metadata.

Common situations: Forgetting brackets around single-element defaults, YAML flow-style mistakes that parse as a map instead of a list, mismatched metadata after a schema change from scalar to list.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/8d3abe79a3b6919a. Report an issue: GitHub.