hasura/graphql-engine · error · RequestError::ValidationFailed

validation failed

Error message

validation failed: {0}

What it means

RequestError::ValidationFailed is returned when the parsed GraphQL document fails semantic validation against the schema. It wraps gql::validation::Error, so the message is 'validation failed: {0}' with the specific rule violation (unknown field, wrong argument type, etc.). Like other RequestErrors it is raised before execution of root fields begins.

Solutions

  1. Compare the query against the current schema via GraphiQL autocomplete or an introspection query and fix the flagged field/argument
  2. Regenerate client code (graphql-codegen, Apollo CLI) against the updated schema
  3. Check the wrapped validation error message and location for the exact rule that failed
  4. If a field was removed/renamed server-side, update the query or restore the field in metadata

Example fix

// before
query { usr(id: 1) { nm } }

// after
query { user(id: 1) { name } }
Defensive patterns

Strategy: validation

Validate before calling

// Client-side pre-validation against the schema:
import { buildSchema, validate, parse } from 'graphql';
const schema = buildSchema(await fetchIntrospection());
const errors = validate(schema, parse(query));
if (errors.length) throw new Error(errors.map(e => e.message).join('; '));

Try / catch

match frontend.execute(&req).await {
    Err(e @ RequestError::ValidationFailed(v)) => {
        // v has message + locations; return GraphQL-style errors with 400
        respond_validation_error(v)
    }
    rest => rest,
}

Prevention

When it happens

Trigger: A syntactically valid GraphQL document that references undefined fields/arguments, passes arguments of the wrong type, uses unknown directives, subscribes to non-subscription fields, or violates any validation rule in the October 2021 spec section on validation.

Common situations: Schema drift: client was built against an older schema where a field existed; typos in field names; missing variables or wrong variable types; introspection-based codegen out of date after a schema change.

Related errors


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

Appendix: source

Thrown at v3/crates/graphql/frontend/src/error.rs:14

use axum::response::IntoResponse;
use engine_types::ExposeInternalErrors;
use gql::http::GraphQLError;
use lang_graphql as gql;
use tracing_util::{ErrorVisibility, TraceableError};

/// Request errors are raised before execution of root fields begins.
/// Ref: <https://spec.graphql.org/October2021/#sec-Errors.Request-errors>
#[derive(Debug, thiserror::Error)]
pub enum RequestError {
    #[error("parsing failed: {0}")]
    ParseFailure(#[from] gql::ast::spanning::Positioned<gql::parser::Error>),

    #[error("validation failed: {0}")]
    ValidationFailed(#[from] gql::validation::Error),

    #[error("{0}")]
    IRConversionError(#[from] graphql_ir::Error),

    #[error("{0}")]
    GraphQlPlanError(#[from] graphql_ir::GraphqlIrPlanError),

    #[error("explain error: {0}")]
    ExplainError(String),
}

impl RequestError {
    pub fn to_graphql_error(&self, expose_internal_errors: ExposeInternalErrors) -> GraphQLError {
        let message = match (self, expose_internal_errors) {
            // Error messages for internal errors from IR conversion and Plan generations are masked.
            (
                Self::IRConversionError(graphql_ir::Error::Internal(_)),

View on GitHub (pinned to 724551b9ae)