Before you begin
- Create a dashboard that uses the Cognite Data Source for Grafana.
Create a variable from a GraphQL query
Use GraphQL queries against data models to populate variable values from CDF. The GraphQL tab uses the same editor as the GraphQL query tab in panels.
Open the variable editor
Select the data model and version
CogniteCore, version v1) with a query that lists the first 10 assets. You can run this query as-is.Write and test the query
items) or connection-style results (edges). Select Examples to open ready-made queries.Select the value and display text
externalId or instanceId.space. The list is populated from your query once the query is valid.Optionally, in the Display text field, select a different field to show in the variable dropdown. For example, set Value to externalId and Display text to name so users pick readable names. If you leave Display text empty, the dropdown shows the value.Save the variable
$variable or ${variable} in panel queries to insert the selected value.Emit instance references
A GraphQL variable can hold a whole instance reference, thespace and externalId of an instance, instead of a single field. Use instance references to filter queries on direct relations, for example, to show the time series or the records of the asset a user selects.
Select space and externalId in the query
space and externalId on the same object. This can be the rows themselves or one nested field, such as instanceId { space externalId }.Select Instance ID as the value
name so the dropdown shows readable names.{"space":"...","externalId":"..."}.Use instance references in queries
A variable that holds instance references filters a query on a direct relation. The data source writes the selected instances in the syntax of each query tab.Syntax in GraphQL queries
In the GraphQL query of a panel or of another variable, the data source writes the variable in GraphQL syntax:${asset:csv}, are filled in by Grafana as usual.
Chain variables
A variable’s GraphQL query can use other dashboard variables, so the value selected in one variable narrows the options of the next. For example, asite variable can limit an asset variable to the assets of the selected site, and a third variable can list the children of the selected asset. When a user changes a variable, Grafana updates the variables that depend on it.
Create the first variable
site. To filter the next variable on a direct relation, emit instance references.Use the first variable in the query of the second
site variable:"$siteName" in a string filter.items of listCogniteAsset. Instances nested deeper in the response, for example, the children of an asset returned by getCogniteAssetById, don’t become options. To list related instances, filter a list query on the relation, as in the example.