{"record":{"id":"70b032e1c9c876ae","repo":"windmill-labs/windmill","slug":"error-parsing-sql","errorCode":null,"errorMessage":"Error parsing sql","messagePattern":"Error parsing sql","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-graphql/src/lib.rs","lineNumber":27,"sourceCode":"\nuse serde_json::json;\n\nuse windmill_parser::{Arg, MainArgSignature, ObjectType, Typ};\n\npub fn parse_graphql_sig(code: &str) -> anyhow::Result<MainArgSignature> {\n    let parsed = parse_graphql_file(&code)?;\n    if let Some(x) = parsed {\n        let args = x;\n        Ok(MainArgSignature {\n            star_args: false,\n            star_kwargs: false,\n            args,\n            auto_kind: None,\n            has_preprocessor: None,\n            ..Default::default()\n        })\n    } else {\n        Err(anyhow!(\"Error parsing sql\".to_string()))\n    }\n}\n\nlazy_static::lazy_static! {\n    static ref RE_ARG_GRAPHQL: Regex = Regex::new(r#\"\\$(\\w+)\\s*:\\s*(?:(\\w+)(!)?|\\[(\\w+)!?\\])(!)?\\s*(?:=\\s*\"?(\\w+)\"?\\s*)?\"#).unwrap();\n}\n\nfn parse_graphql_file(code: &str) -> anyhow::Result<Option<Vec<Arg>>> {\n    let mut args: Vec<Arg> = vec![];\n\n    for cap in RE_ARG_GRAPHQL.captures_iter(code) {\n        let name = cap.get(1).map(|x| x.as_str().to_string()).unwrap();\n        let mut typ = cap.get(2).map(|x| x.as_str().to_string());\n\n        let parsed_typ = if typ.is_none() {\n            let inner_typ = cap.get(4).map(|x| x.as_str().to_string());\n            typ = inner_typ.clone().map(|x| format!(\"[{}]\", x.to_string()));\n            Typ::List(Box::new(parse_graphql_typ(inner_typ.unwrap().as_str())))","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-graphql/src/lib.rs#L9-L45","documentation":"parse_graphql_sig parses GraphQL operation files by regex-extracting `$var: Type` argument declarations; parse_graphql_file returns None when no operation/arguments could be parsed, and the function rejects that with this (misleadingly worded) 'Error parsing sql' message. It means the input was not recognized as a GraphQL operation with parseable arguments, not that SQL was involved.","triggerScenarios":"do_graphql on a script whose content contains no `$var: Type` matches and no recognizable operation — empty query, wrong-language content pasted into a GraphQL script, or variable declarations shaped so the argument regex misses everything.","commonSituations":"Pasting a SQL script into a GraphQL script slot (the error text betrays the copy-paste origin); variable declarations with typos (`$id int` without a colon, missing `$`); anonymous shorthand queries `{ ... }` that still need standard `$var: Type` args; exotic types like nested `[Inner!]!]` the regex cannot capture.","solutions":["Verify the script is actually GraphQL, not SQL — paste it into a GraphQL script, not a SQL one","Declare arguments in the standard form `$var: Type!` (or `[Type!]`) inside the operation, e.g. `query Q($id: ID!) { ... }`","Check for typos in variable declarations: the `$` prefix, colon, and capitalized type are all required for the regex to match","Wrap the query in an explicit `query`/`mutation` operation definition if detection still fails"],"exampleFix":"// before\n{ user(id: $id) { name } }\n// after\nquery GetUser($id: ID!) {\n  user(id: $id) { name }\n}","handlingStrategy":"validation","validationCode":"// Pre-check: the script must contain at least one `$var: Type` argument declaration\nlet re = regex::Regex::new(r\"\\$\\w+\\s*:\").unwrap();\nfn has_graphql_args(code: &str, re: &regex::Regex) -> bool {\n    re.is_match(code)\n}","typeGuard":"fn looks_like_graphql_operation(code: &str) -> bool {\n    code.contains(\"query \") || code.contains(\"mutation \") || code.contains(\"subscription \")\n        || code.trim_start().starts_with('{')\n}","tryCatchPattern":"match parse_graphql_sig(code) {\n    Ok(sig) => sig,\n    Err(e) if e.to_string() == \"Error parsing sql\" => {\n        // misnamed legacy message: means no GraphQL args were detected\n        bail!(\"no $var: Type arguments found — is this really a GraphQL script?\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Confirm the script language is GraphQL, not SQL, when creating it","Use standard argument syntax `$var: Type!` inside an explicit query/mutation definition","Keep types regex-friendly: simple identifiers or [List] forms, e.g. `$ids: [ID!]!`","Test argument extraction in the editor preview before saving"],"tags":["graphql","parser","regex","misleading-message"],"backgroundTag":"graphql-operation-parse-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}