Verified Commit a8779a7c authored by Michael Usachenko's avatar Michael Usachenko Committed by GitLab
Browse files

feat(query): add include_debug_sql option to control SQL in responses

parent a3c3e69f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -663,6 +663,11 @@
          "$ref": "#/$defs/DynamicColumnMode",
          "description": "Columns fetched for dynamically-discovered entities (PathFinding, Neighbors hydration). '*' returns all columns; 'default' returns the entity's default_columns from the ontology. Defaults to 'default'.",
          "default": "default"
        },
        "include_debug_sql": {
          "type": "boolean",
          "description": "When true, includes compiled ClickHouse SQL in the response metadata for debugging. Only honored for authorized users (instance admins and direct GitLab org members with Reporter+ access). Defaults to false.",
          "default": false
        }
      },
      "additionalProperties": false
+2 −2
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ mod tests {
        let condensed = condensed_query_schema().expect("Should condense");

        assert!(
            condensed.len() < 17000,
            "Condensed schema should be under 17KB, got {} bytes",
            condensed.len() < 18000,
            "Condensed schema should be under 18KB, got {} bytes",
            condensed.len()
        );
    }
+34 −0
Original line number Diff line number Diff line
@@ -31,6 +31,11 @@ pub struct QueryOptions {
    /// `All` returns every column; `Default` returns the entity's `default_columns`.
    #[serde(default)]
    pub dynamic_columns: DynamicColumnMode,
    /// When true, includes compiled ClickHouse SQL in the response metadata.
    /// Only honored for authorized users (instance admins and direct GitLab
    /// org members with Reporter+ access).
    #[serde(default)]
    pub include_debug_sql: bool,
}

/// Authorization config for an entity type, derived from the ontology and carried
@@ -890,6 +895,35 @@ mod tests {
        .unwrap();

        assert_eq!(input.options.dynamic_columns, DynamicColumnMode::Default);
        assert!(!input.options.include_debug_sql);
    }

    #[test]
    fn options_include_debug_sql_true() {
        let input = parse_input(
            r#"{
            "query_type": "traversal",
            "node": {"id": "u", "entity": "User"},
            "options": {"include_debug_sql": true}
        }"#,
        )
        .unwrap();

        assert!(input.options.include_debug_sql);
    }

    #[test]
    fn options_include_debug_sql_defaults_false() {
        let input = parse_input(
            r#"{
            "query_type": "traversal",
            "node": {"id": "u", "entity": "User"},
            "options": {"dynamic_columns": "*"}
        }"#,
        )
        .unwrap();

        assert!(!input.options.include_debug_sql);
    }

    #[test]
+1 −0
Original line number Diff line number Diff line
@@ -521,6 +521,7 @@ mod tests {
            }],
            options: QueryOptions {
                dynamic_columns: mode,
                ..Default::default()
            },
            ..Input::default()
        }
+2 −1
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ impl PipelineStage for OutputStage {

        let compiled = ctx.compiled()?;

        let raw_query_strings = if can_see_debug_sql(ctx) {
        let requested = compiled.input.options.include_debug_sql;
        let raw_query_strings = if requested && can_see_debug_sql(ctx) {
            let debug_json = json!({
                "base": compiled.base.sql,
                "base_rendered": compiled.base.render(),
Loading