11# GraphQL Data Source
22
3+ ![ CI] ( https://github.com/fifemon/graphql-datasource/workflows/CI/badge.svg )
4+
35[ Grafana] ( https://grafana.com ) datasource plugin that provides access to a
4- GraphQL API for numerical timeseries data, general/tabular data, and
5- annotations.
6-
7- * The GraphQL query must be structured so that the data of interest is returned
8- under the configurable data path (default ` data ` ) in the response. If the
9- object at that path is an array it will be iterated over, with each object added
10- as a row in the data frame, otherwise the result object will be the only row.
11- * Can be separated by commas to use multiple data paths
12- * Timeseries data requires a field named ` Time ` containing the timestamp in a
13- format that can be parsed by ` moment() ` (e.g. ISO8601).
14- * Nested types will be flattened into dot-delimited fields.
15- * Grafana variables should be substituted directly in the query (instead of
16- using GraphQL variables). The dashboard time ranges are available in the
17- [ global variables] ( https://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/ )
18- ` $__from ` and ` $__to ` as millisecond epoch (or in whatever format is needed by the API
19- in Grafana 7.1.2 or later).
20- * Group by can be used to group elements into multiple data points.
21- * Alias by is used to alter the name of the field displayed in the legend. ` $field_<field.name> ` is substituted with the
22- values of the field and ` $fieldName ` is substituted with the name of the field.
6+ GraphQL API for numerical timeseries data, general/tabular data,
7+ annotations, and dashboard variables.
8+
9+ - The GraphQL query must be structured so that the data of interest is returned
10+ under the configurable data path (default ` data ` ) in the response. If the
11+ object at that path is an array it will be iterated over, with each object added
12+ as a row in the data frame, otherwise the result object will be the only row.
13+ - Can be separated by commas to use multiple data paths
14+ - Timeseries data requires a field named ` Time ` containing the timestamp in a
15+ format that can be parsed by ` moment() ` (e.g. ISO8601).
16+ - Nested types will be flattened into dot-delimited fields.
17+ - Grafana variables should be substituted directly in the query (instead of
18+ using GraphQL variables). The dashboard time ranges are available in the
19+ [ global variables] ( https://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/ )
20+ ` $__from ` and ` $__to ` as millisecond epoch (or in whatever format is needed by the API
21+ in Grafana 7.1.2 or later).
22+ - Group by can be used to group elements into multiple data points.
23+ - Alias by is used to alter the name of the field displayed in the legend.
24+ ` $field_<field.name> ` is substituted with the values of the field and
25+ ` $fieldName ` is substituted with the name of the field.
2326
2427# Screenshots
2528
@@ -37,13 +40,16 @@ examples and tutorials.
3740
3841``` graphql
3942query {
40- submissions (user :"$user" , from :"$__from" , to :"$__to" ){
41- Time :submitTime
42- idle running completed
43- }
43+ submissions (user : " $user" , from : " $__from" , to : " $__to" ) {
44+ Time : submitTime
45+ idle
46+ running
47+ completed
48+ }
4449}
4550```
46- * Data path: ` submissions `
51+
52+ - Data path: ` submissions `
4753
4854Note the use of the global ` $__from ` and ` $__to ` variables to insert the
4955dashboard time range into the query, alongside a dashboard variable ` $user ` .
@@ -52,21 +58,26 @@ dashboard time range into the query, alongside a dashboard variable `$user`.
5258
5359``` graphql
5460query {
55- data :queryAll (from :"$__from" , to :"$__to" , sourceId :"default" ) {
56- batteryVoltage {
57- Time :dateMillis
58- packet {
59- batteryVoltage
60- identifier { representation }
61- identityInfo { displayName }
62- }
61+ data : queryAll (from : " $__from" , to : " $__to" , sourceId : " default" ) {
62+ batteryVoltage {
63+ Time : dateMillis
64+ packet {
65+ batteryVoltage
66+ identifier {
67+ representation
68+ }
69+ identityInfo {
70+ displayName
6371 }
72+ }
6473 }
74+ }
6575}
6676```
67- * Data path: ` data.batteryVoltage `
68- * Group by: ` packet.identifier.representation `
69- * Alias by: ` $field_packet.identityInfo.displayName `
77+
78+ - Data path: ` data.batteryVoltage `
79+ - Group by: ` packet.identifier.representation `
80+ - Alias by: ` $field_packet.identityInfo.displayName `
7081
7182In the above example, "Group by" and "Alias by" are defined. "Group by" allows
7283you to split up an array of data into multiple data points. "Alias by" is used
@@ -82,28 +93,29 @@ querying multiple numeric fields that you want displayed in your graph.
8293
8394``` graphql
8495query {
85- server1 :queryEvents (from : " $__from" , to :"$__to" , server :"server1" ) {
86- birthdayEvent {
87- Time :dateMillis
88- person {
89- fullName
90- }
91- }
96+ server1 : queryEvents (from : " $__from" , to : " $__to" , server : " server1" ) {
97+ birthdayEvent {
98+ Time : dateMillis
99+ person {
100+ fullName
101+ }
92102 }
93- server2 : queryEvents ( from : " $__from " , to : "$__to" , server : "server2" ) {
94- birthdayEvent {
95- Time : dateMillis
96- person {
97- fullName
98- }
99- }
103+ }
104+ server2 : queryEvents ( from : " $__from " , to : " $__to " , server : " server2 " ) {
105+ birthdayEvent {
106+ Time : dateMillis
107+ person {
108+ fullName
109+ }
100110 }
111+ }
101112}
102113```
103- * Data path: ` server1.birthdayEvent, server2.birthdayEvent `
104- * Title: ` Birthday yay! `
105- * Text: ` $field_person.fullName `
106- * Tags: ` tag1, tag2 `
114+
115+ - Data path: ` server1.birthdayEvent, server2.birthdayEvent `
116+ - Title: ` Birthday yay! `
117+ - Text: ` $field_person.fullName `
118+ - Tags: ` tag1, tag2 `
107119
108120The above annotation example is similar to regular queries. You must have a
109121` Time ` field and are able to define a data path. Similar to the last example,
0 commit comments