Версия без регулярного выражения:
var string = 'This is a string',
searchFor = 'is',
count = 0,
pos = string.indexOf(searchFor);
while (pos > -1) {
++count;
pos = string.indexOf(searchFor, ++pos);
}
console.log(count); // 2
Я думаю, вы могли бы использовать фрагменты для этого! Но вам все равно придется писать 2 "queries"
в этом случае fragments
.
Сначала давайте создадим fragment
для каждого timeSeries
, пожалуйста, проверьте свой тип запроса querySeries, я собираюсь обратиться к нему как timeseriesDataQuery
const series1Q = gql`
fragment series1 on timeseriesDataQuery {
series1: timeseriesData(sourceId: "source1") {
data {
time
value
}
}
}
}
const series2Q = gql`
fragment series2 on timeseriesDataQuery {
series2: timeseriesData(sourceId: "source2") {
data {
time
value
}
}
}
}
И затем просто вставьте их в запрос:
export const mainQuery = gql`
query fetchData {
...series1
...series2
}
${series1Q}
${series2Q}
`