{"record":{"id":"6b8b705f22a99b82","repo":"hasura/graphql-engine","slug":"only-schema-field-is-expected-but-found-name","errorCode":null,"errorMessage":"Only __schema field is expected but found: {name:}","messagePattern":"Only __schema field is expected but found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/lang-graphql/src/generate_graphql_schema.rs","lineNumber":19,"sourceCode":"/*\nThis module provides functions to generate introspection result as GraphQL schema\nfor each namespace from the schema.\n */\nuse json_ext;\nuse std::collections::BTreeMap;\nuse std::sync::OnceLock;\nuse tracing_util::SpanVisibility;\nuse tracing_util::{ErrorVisibility, TraceableError};\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"unable to parse introspection query: {0}\")]\n    ParseIntrospectionQuery(String),\n    #[error(\"unable to normalize introspection query: {0}\")]\n    NormalizeIntrospectionQuery(String),\n    #[error(\"unable to find field call\")]\n    FieldCallNotFound,\n    #[error(\"Only __schema field is expected but found: {name:}\")]\n    OnlySchemaFieldExpected { name: String },\n    #[error(\"introspection query failed: {0}\")]\n    IntrospactionQueryError(#[from] crate::introspection::Error),\n    #[error(\"unable to serialize to json: {0}\")]\n    SerializeJson(#[from] serde_json::Error),\n}\nimpl TraceableError for Error {\n    fn visibility(&self) -> ErrorVisibility {\n        ErrorVisibility::User\n    }\n}\n\n/// Generate GraphQL schema for a given namespace\npub fn build_namespace_schema<\n    S: crate::schema::SchemaContext,\n    NSGet: crate::schema::NamespacedGetter<S>,\n>(\n    namespaced_getter: &NSGet,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/lang-graphql/src/generate_graphql_schema.rs#L1-L37","documentation":"The introspection handler received a root field other than __schema (name of the offending field is included). Introspection requests are expected to query only the __schema field here, so any other root field is rejected.","triggerScenarios":"Sending a query through the introspection endpoint/handler that selects a root field like __typename or a regular model field instead of __schema; routing ordinary queries into the introspection code path.","commonSituations":"Custom servers routing all POSTs to the introspection generator; clients probing with mixed queries; tests hitting the wrong handler.","solutions":["Send only the standard __schema-based introspection query to this handler","Route regular queries to the normal execution endpoint","Use a standard GraphQL client library's introspection query instead of hand-rolling it"],"exampleFix":"# before\n{ hello }            # sent to introspection handler\n# after\n{ __schema { types { name } } }","handlingStrategy":"validation","validationCode":"// Route by root field before dispatch\nconst rootFields = Object.keys(parse(doc).definitions[0].selectionSet.selections.map(s => s.name.value));\nif (isIntrospectionHandler && !rootFields.every(f => f === '__schema')) routeToExecution();","typeGuard":"const isSchemaOnlyIntrospection = (doc) =>\n  rootFieldNames(doc).every(n => n === '__schema');","tryCatchPattern":"// Catch and re-route the request to the normal execution endpoint","preventionTips":["Use standard introspection queries from graphqlutilities","Don't multiplex data queries with __schema on this path"],"tags":["graphql","introspection","validation"],"backgroundTag":"introspection-schema-field-expected","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}