The addRecentQuery() GraphQL mutation is used to add a query to the list of recent queries. The query is a JSON encoded query and visualization structure produced by the user-interface. This field is not yet available. It's described here as a preview.

You can see in the LogScale User Interface, a list of recently run queries or saved queries by clicking on the Queries pull-down menu. Below is a screenshot showing an example of this:

addRecentQuery

Figure 1. addRecentQuery


For more information related to recent queries and saving queries, see the Searching Data documentation page.

Syntax

Below is the syntax for the addRecentQuery() mutation field:

graphql
addRecentQuery(
      input: AddRecentQueryInput!
    ): AddRecentQuery!

Below is an example of how this mutation field might be used:

Raw
graphql
mutation test {
  addRecentQuery(input: {
    viewName: "humio",
    queryArguments: [],
    queryString: "#kind=threaddumps | NOT \"(Native Method)\" | top(humioLine)",
		start: "3d",
    end: "now",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}
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" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
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" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
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" : "mutation test { ^
  addRecentQuery(input: { ^
    viewName: \"humio\", ^
    queryArguments: [], ^
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\", ^
		start: \"3d\", ^
    end: \"now\", ^
    isLive: false, ^
  }) { ^
    recentQueries { ^
      query { ^
        queryString, ^
        start, ^
        end, ^
        arguments { ^
          key, ^
          value, ^
        } ^
      } ^
    } ^
  } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}'
"$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" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}';
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" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}'''

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" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
);


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 input (i.e., AddRecentQueryInput), there are several parameters that may be given. Below is a list of them along with their data type and a description of each:

Table: AddRecentQueryInput

ParameterTypeRequiredDefaultDescription
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 17, 2024
endstringyes The end of the relative time interval for the query.
isLivebooleanyes Whether the query is live.
optionsJSON  Any options related to the query.
queryArguments[InputDictionaryEntry]yes Arguments related to the recent query. See InputDictionaryEntry.
queryStringstringyes The query string.
startstringyes The start of the relative time interval for the query.
viewNamestringyes The name of the view.
widgetTypestring  The type of widget used, if one.

You'll notice in the table here that one of the data types, InputDictionaryEntry, is a specialized one. However, it simply calls for key/value pairs containing strings.

Returned Datatypes

As indicated by the syntax above, this mutation will return data using the datatype, addRecentQuery(). Below is a list of the parameters of that datatype:

Table: AddRecentQuery

ParameterTypeRequiredDefaultDescription
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 23, 2024
recentQueries[RecentQuery]yes A list of recently run queries. See RecentQuery.