API Stability Preview

The validateQuery() GraphQL query is used to check that a query compiles. This field is deprecated. Use analyzeQuery() , instead.

For more information on saved queries, see the User Functions (Saved Searches) reference page where saved queries are discussed. Also, look at the Searching Data documentation page as it relates to recent queries and saving queries.

Syntax

Below is the syntax for the validateQuery() query field:

graphql
validateQuery(
     queryString: string!
     version: LanguageVersionEnum!
     isLive: boolean
     arguments: [QueryArgument!]
   ): QueryValidationResult!

Again, since this field is deprecated, use instead analyzeQuery() . Below is an example, though, of how this query field might be used:

Raw
graphql
query {
  validateQuery(queryString:"host=localhost",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}
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 {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}
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 {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}
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 { ^
  validateQuery(queryString:\"host=localhost\", ^
                version: legacy, isLive: false) ^
  {isValid, diagnostics{severity, message, code}} ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "query {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $INGEST_TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $json = '{"query" : "query {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}';
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 {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}'''

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 {
  validateQuery(queryString:\"host=localhost\",
                version: legacy, isLive: false)
  {isValid, diagnostics{severity, message, code}}
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL/graphql',
  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();

Given Datatypes

For the given data, there two special datatypes: LanguageVersionEnum and QueryArgument. Below is a list of them along with a description of each:

Table: LanguageVersionEnum

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 13, 2024
federated1boolean  PreviewIndicates if Federated1 version of the LogScale query is used.
legacyboolean  PreviewWhether legacy LogScale query language is used.
xdr1boolean  PreviewWhether XDR1 is used.
xdrdetects1boolean  PreviewWhether XDR Detects 1 query language is used.

Table: QueryArgument

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 19, 2024
namestringyes PreviewThe name of the query argument.
valuestringyes PreviewThe value fo the query argument.

Returned Datatypes

The returned datatype QueryValidationResult has its own parameters. They're listed in the table here:

Table: QueryValidationResult

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Oct 2, 2024
diagnostics[QueryDiagnostic]yes PreviewA diagnostic message from query validation. See QueryDiagnostic. This is a preview for internal testing and subject to change.
isValidbooleanyes PreviewWhether query is valid. For internal testing.