Summary

The analyzeQuery() GraphQL query performs static analysis on a query string and returns three types of output: error and warning validation (validateQuery), a suggested alert type (suggestedAlertType), and detailed static analysis results (analysisResult). When a viewName is provided, the query validates saved query references used in the query string. Supply arguments to avoid false positives from unbound query parameters. The strict parameter (default: on) controls whether missing arguments and unresolved saved queries are treated as errors. When queryKind is set to the parser kind, the query surfaces deprecation warnings for parsers programmatically.

Syntax

graphql
analyzeQuery(
      input: AnalyzeQueryArguments!
   ): AnalyzeQueryInfo!

For the input, supply the required queryString and version, plus any optional parameters that refine the analysis. For the results, specify the fields you want from the three available: validateQuery, suggestedAlertType, and analysisResult. See the sections below for details.

Example

Raw
graphql
query {
   analyzeQuery(
     input:{
        queryString: "groupBy([#type,actor.type])",
        arguments:[{name: "groupBy([#type,actor.type])", value: ""}],
        version:{name: "legacy"},
        viewName: "humio-audit"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "query { ^
   analyzeQuery( ^
     input:{ ^
        queryString: \"groupBy([#type,actor.type])\", ^
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}], ^
        version:{name: \"legacy\"}, ^
        viewName: \"humio-audit\" ^
    } ^
  ) {validateQuery {isValid} , suggestedAlertType {alertType}} ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "query {
   analyzeQuery(
     input:{
        queryString: \"groupBy([#type,actor.type])\",
        arguments:[{name: \"groupBy([#type,actor.type])\", value: \"\"}],
        version:{name: \"legacy\"},
        viewName: \"humio-audit\"
    }
  ) {validateQuery {isValid} , suggestedAlertType {alertType}}
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "analyzeQuery": {
      "validateQuery": {
        "isValid": true
      },
      "suggestedAlertType": {
        "alertType": "AggregateAlert"
      }
    }
  }
}

The results here show that the query is valid. From that, it suggests that an aggregate alert might be created with the query.

Input Parameters

For the input, supply the required query string and language version. Optional parameters include: viewName (enables validation of saved query references), arguments (binds query parameters to reduce false positives from unbound uses), strict (on by default; disable to treat missing arguments as non-errors), rejectFunctions (a list of disallowed function names), timeInterval (enables time-range syntax and function validation), and queryKind (specifies the kind of query being analyzed; the parser kind surfaces parser deprecation warnings programmatically). The parameters are listed here:

Table: AnalyzeQueryArguments Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
argumentsQueryArgumentInputTypeyes   Query arguments. When not supplied, query analysis will attempt to recover from unbound query parameter uses in the given query. Specifying query arguments for all query parameters used in the query is recommended for more precise analysis.
isLiveBoolean     
queryKindQueryKindInputType     
queryStringStringyes    
rejectFunctionsStringyes   A list of function names which are disallowed when validated the query
strictBoolean    Determines whether query analysis is performed in strict mode or not. Defaults to true. When in strict mode, missing query arguments are reported as validation errors, and saved query uses are validated. When in non-strict mode, missing query arguments and all saved query uses are not reported as validation errors.
timeIntervalQueryTimeInterval    Optional time range that the query is intended to be run over. When provided the interval will be validated syntactically and certain query functions can be further validated.
versionLanguageVersionInputTypeyes    
viewNameRepoOrViewName    The view name in which the query should be analyzed. This gives query validation access to the saved query definitions available on that view. Specifying a view is recommended for more precise analysis.

Returned Values

The result contains three fields: validateQuery reports errors and warnings in a standard search context; suggestedAlertType returns the recommended alert type for the query, or null if no suitable type is found; and analysisResult provides the static analysis output. The available fields are listed here:

Table: AnalyzeQueryInfo Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
analysisResultQueryAnalysisResultyes Short-Term The results from statically analyzing the query.
suggestedAlertTypeSuggestedAlertTypeInfo  Short-Term Suggested type of alert to use for the given query. Returns null if no suitable alert type could be suggested. The given query is not guaranteed to be valid for the suggested alert type.
validateQueryQueryValidationInfoyes Short-Term Check if the given query contains any errors or warnings when used in a standard search context.