I'm trying to write a Gelly query to count the number of views (rsWatchHistory) grouped by date for a specific shopifyShop. I want to filter for records from the past 30 days and group them by the formatted date (YYYY-MM-DD).
Here's the Gelly code I wrote:
fragment ViewsCountPerDay($shopId: ID!, $filterDate: now().subtract(30, 'days')) on rsWatchHistory {
createdAt
count(id)
[where shop.id == $shopId && createdAt >= $filterDate]
[group by createdAt.format("YYYY-MM-DD")]
}
field on shopifyShop {
rsWatchHistory {
...ViewsCountPerDay(shopId: this.id, filterDate: now().subtract(30, 'days'))
}
}
However, I keep getting the following error:
Expecting token of type --> RParen <-- but found --> '(' <--
My Goal
I want to achieve the equivalent of the following SQL query:
SELECT
DATE(createdAt) AS view_date,
COUNT(*) AS view_count
FROM
rsWatchHistory
WHERE
shop_id = <your_shop_id>
AND createdAt >= <your_filter_date>
GROUP BY
view_date
ORDER BY
view_date;
Questions:
1. How should I properly write this Gelly code to avoid the syntax error?
2. Is my use of now().subtract(30, 'days') correct for filtering records from the past 30 days?
3. Can fragments accept arguments like $shopId and $filterDate, or do I need to handle filtering differently?
Thanks in advance for any help or suggestions!