mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Query: Add query type to json marshal/unmarshal (#83821)
add query type to json marshal/unmarshal
This commit is contained in:
parent
57935250fd
commit
c644826f50
@ -138,6 +138,9 @@ func (g GenericDataQuery) MarshalJSON() ([]byte, error) {
|
||||
if g.MaxDataPoints > 0 {
|
||||
vals["maxDataPoints"] = g.MaxDataPoints
|
||||
}
|
||||
if g.QueryType != "" {
|
||||
vals["queryType"] = g.QueryType
|
||||
}
|
||||
return json.Marshal(vals)
|
||||
}
|
||||
|
||||
@ -221,6 +224,17 @@ func (g *GenericDataQuery) unmarshal(vals map[string]any) error {
|
||||
delete(vals, key)
|
||||
}
|
||||
|
||||
key = "queryType"
|
||||
v, ok = vals[key]
|
||||
if ok {
|
||||
queryType, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected queryType as string (got: %t)", v)
|
||||
}
|
||||
g.QueryType = queryType
|
||||
delete(vals, key)
|
||||
}
|
||||
|
||||
g.props = vals
|
||||
return nil
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
|
||||
"timeRange": {
|
||||
"from": "100",
|
||||
"to": "200"
|
||||
}
|
||||
},
|
||||
"queryType": "foo"
|
||||
}
|
||||
],
|
||||
"from": "1692624667389",
|
||||
@ -66,6 +67,7 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
|
||||
"uid": "old"
|
||||
},
|
||||
"maxDataPoints": 10,
|
||||
"queryType": "foo",
|
||||
"refId": "Z",
|
||||
"timeRange": {
|
||||
"from": "100",
|
||||
|
Loading…
Reference in New Issue
Block a user