{"record":{"id":"c1767fee9069784e","repo":"linera-io/linera-protocol","slug":"expected-query-to-start-with-query-got-s","errorCode":null,"errorMessage":"expected query to start with 'query', got: {s}","messagePattern":"expected query to start with 'query', got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-service/src/query_subscription.rs","lineNumber":33,"sourceCode":"use tokio::sync::watch;\nuse tokio_util::sync::CancellationToken;\nuse tracing::{debug, warn};\n\n/// A named GraphQL query string registered at startup via `--allow-subscription`.\n#[derive(Clone, Debug)]\npub struct RegisteredQuery {\n    /// The operation name used to refer to the query.\n    pub name: String,\n    /// The full GraphQL query string.\n    pub query: String,\n}\n\n/// Parses a GraphQL query string like `query Name { ... }` and extracts the operation name.\npub fn parse_allowed_subscription(s: &str) -> anyhow::Result<RegisteredQuery> {\n    let trimmed = s.trim();\n    let rest = trimmed\n        .strip_prefix(\"query\")\n        .ok_or_else(|| anyhow::anyhow!(\"expected query to start with 'query', got: {s}\"))?;\n    // The character right after \"query\" must be whitespace (not part of a longer word).\n    anyhow::ensure!(\n        rest.starts_with(char::is_whitespace),\n        \"expected whitespace after 'query' keyword\"\n    );\n    let rest = rest.trim_start();\n    // Extract the operation name: sequence of alphanumeric/underscore chars.\n    let name = rest\n        .split(|c: char| !c.is_alphanumeric() && c != '_')\n        .next()\n        .unwrap_or_default();\n    anyhow::ensure!(\n        !name.is_empty(),\n        \"expected an operation name after 'query', e.g. 'query MyQuery {{ ... }}'\"\n    );\n    Ok(RegisteredQuery {\n        name: name.to_string(),\n        query: trimmed.to_string(),","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/query_subscription.rs#L15-L51","documentation":"A --allow-subscription value did not start with the literal keyword `query`. parse_allowed_subscription only accepts strings of the shape `query Name { ... }` — it strips the prefix \"query\", requires whitespace right after it, then extracts the operation name used to register the subscription.","triggerScenarios":"Passing a `subscription ...` document, a bare query body `{ transfers { amount } }` with no keyword, or a keyword glued to the name (`queryTransfers`) — the last one instead trips the whitespace check, but a missing/other keyword trips this error.","commonSituations":"Registering actual GraphQL subscriptions (not supported here — only named queries); copy-pasting query bodies from GraphQL playgrounds that omit the keyword; assuming the parser accepts shorthand queries.","solutions":["Prefix the document with the keyword and a name: `query Transfers { transfers { amount } }`.","Do not use `subscription` documents — this flag registers polled queries, and only the `query` keyword is accepted.","Keep whitespace between `query` and the operation name.","Pick a stable operation name; it is the key used for later --subscription-ttl Name=Secs settings."],"exampleFix":"# before\n--allow-subscription 'subscription Transfers { transfers { amount } }'\n\n# after\n--allow-subscription 'query Transfers { transfers { amount } }'","handlingStrategy":"validation","validationCode":"let t = s.trim();\nensure!(\n    t == \"query\" || t.starts_with(\"query \") || t.starts_with(\"query\\n\"),\n    \"--allow-subscription must start with the 'query' keyword, e.g. 'query Name {{ ... }}'\"\n);","typeGuard":"fn is_query_operation(s: &str) -> bool {\n    let t = s.trim();\n    match t.strip_prefix(\"query\") {\n        Some(rest) => rest.is_empty() || rest.starts(char::is_whitespace),\n        None => false,\n    }\n}","tryCatchPattern":null,"preventionTips":["Register named query documents exactly as `query Name { ... }`.","Do not pass `subscription` documents — only polled queries are supported.","Keep whitespace between the keyword and the operation name; reuse the name for TTL settings."],"tags":["graphql","cli","parsing","subscription"],"backgroundTag":"invalid-graphql-query","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}