{"record":{"id":"ef87f6939252eb43","repo":"hasura/graphql-engine","slug":"0-ef87f6","errorCode":null,"errorMessage":"{0}","messagePattern":"\\{0\\}","errorType":"validation","errorClass":"InvalidGraphQlName","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/graphql-types/src/lib.rs","lineNumber":8,"sourceCode":"use schemars::JsonSchema;\nuse serde::{Deserialize, Deserializer, Serialize};\nuse smol_str::SmolStr;\nuse std::fmt::{self, Display, Formatter, Write};\nuse std::str::FromStr;\n\n#[derive(Debug, thiserror::Error)]\n#[error(\"{0}\")]\npub struct InvalidGraphQlName(pub String);\n\n#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema)]\npub struct Name(SmolStr);\n\nimpl Name {\n    pub fn get(&self) -> &SmolStr {\n        &self.0\n    }\n    pub fn take(self) -> SmolStr {\n        self.0\n    }\n    pub fn new(s: &str) -> Result<Name, InvalidGraphQlName> {\n        Name::from_str(s)\n    }\n    pub fn as_str(&self) -> &str {\n        self.0.as_str()\n    }","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/graphql-types/src/lib.rs#L1-L26","documentation":"InvalidGraphQlName is thrown when constructing graphql_types::Name from a string that is not a valid GraphQL Name. GraphQL names must match /^[_A-Za-z][_0-9A-Za-z]*$/, and the error's Display is the offending string itself. It guards the boundary where model/field/argument names from metadata enter GraphQL type definitions.","triggerScenarios":"Calling Name::from_str / Name construction (or APIs that build GraphQL schema types from metadata names) with strings containing invalid characters: hyphens, spaces, dots, leading digits, or empty strings. Typical sources are table/column names, relationship names, or header-derived names that never went through GraphQL sanitization.","commonSituations":"Database tables or columns named like 'user-id', '2023_orders', or 'order.items' surfaced directly as GraphQL names; metadata with unsanitized identifiers; third-party data sources with naming conventions incompatible with GraphQL; failing to apply naming conventions when defining models.","solutions":["Rename the entity in metadata to a valid GraphQL name ([_A-Za-z][_0-9A-Za-z]*) — e.g. 'user-id' → 'user_id'","Apply the engine's naming conventions/sanitization for data source identifiers so invalid characters are transformed before reaching Name construction","Validate names early in metadata ingestion and reject with a clear message naming the offending identifier","Add tests for identifier conversion covering hyphens, dots, unicode, and leading digits"],"exampleFix":"// before\nlet name = Name::from_str(\"order-items\")?; // InvalidGraphQlName(\"order-items\")\n\n// after\nlet name = Name::from_str(\"order_items\")?;","handlingStrategy":"validation","validationCode":"use regex::Regex;\nstatic NAME_RE: Regex = Regex::new(r\"^[_A-Za-z][_0-9A-Za-z]*$\").unwrap();\n\nfn valid_graphql_name(s: &str) -> bool {\n    !s.is_empty() && s.len() <= 256 && NAME_RE.is_match(s)\n}","typeGuard":"fn is_valid_graphql_name(s: &str) -> bool {\n    let mut chars = s.chars();\n    matches!(chars.next(), Some(c) if c == '_' || c.is_ascii_alphabetic())\n        && chars.all(|c| c == '_' || c.is_ascii_alphanumeric())\n}","tryCatchPattern":"let name = match Name::from_str(raw_name) {\n    Ok(n) => n,\n    Err(InvalidGraphQlName(bad)) => {\n        return Err(config_error(format!(\n            \"identifier '{bad}' is not a valid GraphQL name; rename it or apply naming conventions\"\n        )));\n    }\n};","preventionTips":["Apply naming conventions (sanitize hyphens/dots to underscores) to all data-source identifiers before schema building","Validate names in metadata lints so errors surface at build time, not at runtime","Reserve and check GraphQL name rules in any custom naming plugin"],"tags":["rust","graphql","naming","identifier-validation","schema-definition"],"backgroundTag":"invalid-graphql-name","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}