hasura/graphql-engine · error · TypePredicateError

target source for model '{target_model_name:}' is required t

Error message

target source for model '{target_model_name:}' is required to resolve predicate with relationships for {source_type_name:}

What it means

Resolving a predicate that spans a relationship requires knowing the target model's source, but the target model has no source (data connector) defined. Without the target source the resolver cannot build the cross-model query, so it reports that the target source is required.

Source

Thrown at v3/crates/metadata-resolve/src/types/error.rs:504

        relationship_name: Spanned<RelationshipName>,
        type_name: Qualified<CustomTypeName>,
    },
    #[error(
        "relationship '{relationship_name}' is used in predicate but does not exist in comparableRelationships in boolean expression '{boolean_expression_type_name}'"
    )]
    RelationshipNotComparableInTypePredicate {
        relationship_name: Spanned<RelationshipName>,
        boolean_expression_type_name: Qualified<CustomTypeName>,
    },
    #[error(
        "The model '{target_model_name:}' corresponding to the  relationship '{relationship_name:}' used in predicate for type '{type_name:}' is not defined"
    )]
    UnknownModelUsedInRelationshipTypePredicate {
        type_name: Qualified<CustomTypeName>,
        target_model_name: Qualified<ModelName>,
        relationship_name: RelationshipName,
    },
    #[error(
        "target source for model '{target_model_name:}' is required to resolve predicate with relationships for {source_type_name:}"
    )]
    TargetSourceRequiredForRelationshipPredicate {
        source_type_name: Qualified<CustomTypeName>,
        target_model_name: Qualified<ModelName>,
    },
    #[error("{error:} in type {type_name:}")]
    TypeMappingCollectionError {
        type_name: Qualified<CustomTypeName>,
        error: TypeMappingCollectionError,
    },
    #[error("expected object type for field {field_name:} but field had type {field_type:}")]
    ExpectedObjectType {
        field_type: QualifiedTypeReference,
        field_name: Spanned<FieldName>,
    },
    #[error("object type {type_name:} not found")]
    ObjectTypeNotFound {

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Attach a source (dataConnectorName) to the target model named `target_model_name`, if it should be data-backed
  2. If the target is intentionally source-less, don't filter through that relationship — filter after the command/relationship is resolved at the API layer
  3. Rework the relationship to target a model that has a source

Example fix

# before
models:
  stats:               # command-only model, no source
relationships:
  - name: stats
    targetModel: stats
# filter via 'stats' relationship -> error
# after
models:
  stats:
    source: {dataConnectorName: postgres}   # or filter elsewhere
Defensive patterns

Strategy: validation

Validate before calling

// Only allow relationship predicates when the target model has a source
if model.source.is_none() {
    return Err("target model has no source; cannot resolve relationship predicate".into());
}

Type guard

fn has_source(m: &Model) -> bool {
    m.source.is_some()
}

Try / catch

if let Err(TypePredicateError::TargetSourceRequiredForRelationshipPredicate { target_model_name, .. }) = result {
    // attach a source to the target model or filter without the relationship
}

Prevention

When it happens

Trigger: A relationship predicate whose target model is source-less (e.g. a command-backed or purely computed model without `source`); filtering through a relationship into a model that has no data connector attached.

Common situations: Target models that expose only commands (no tables); models intended as views or virtual types used accidentally as filter targets; metadata where sources were removed during refactor.

Related errors


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