Ah, I see. Thank you for the explanation.
No, I don’t think so When you update a record, it creates a new version. We don’t really have record-level user-definable metadata that sits outside of the versioning system. Changes to record content will create new versions in every instance I can think of…
Unfortunately, I don’t think our system will let you do this all on the serverside without actually editing the record itself and creating new versions.
There’s a hackish workaround you can do with linked records in a different model and inverse relationships, but it’ll require you to do some clientside sorting. I sent you an email invite to an example project (https://view-counts.admin.datocms.com/editor), but the end result looks something like this:
query MyQuery {
allPosts(filter: {category: {in: ["one"]}}) {
id
title
category
_allReferencingPageviewDataModels {
pageviews
}
}
}
{
"data": {
"allPosts": [
{
"id": "efiUCKjMRl6c6QSY7LAyYg",
"title": "This has the least pageviews",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 1
}
]
},
{
"id": "bM3bchBmRO-DVVhsNJtewQ",
"title": "This has the most pageviews",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 100
}
]
},
{
"id": "cXzP7v_WT4SzpS80XwsYAA",
"title": "This one is in between",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 51
}
]
}
]
}
}
Which you’d then have to filter client-side using something like:
// allPosts will be sorted in-place by descending value of its related `pageviews` field
allPosts.sort((a,b) => b['_allReferencingPageviewDataModels'][0]['pageviews'] - a['_allReferencingPageviewDataModels'][0]['pageviews'])
/* allPosts now becomes [
{
"id": "bM3bchBmRO-DVVhsNJtewQ",
"title": "This has the most pageviews",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 100
}
]
},
{
"id": "cXzP7v_WT4SzpS80XwsYAA",
"title": "This one is in between",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 51
}
]
},
{
"id": "efiUCKjMRl6c6QSY7LAyYg",
"title": "This has the least pageviews",
"category": "one",
"_allReferencingPageviewDataModels": [
{
"pageviews": 1
}
]
}
]*/
It’s pretty hacky though. It requires:
- A separate model to hold post metadata separately from the Post themselves
- Each record in the metadata model links uniquely to a Post, and has an additional integer field for recording that Post’s pageviews
- The Posts model must have Inverse Relationships enabled
- You can filter serverside (as in this example), but you’ll have to sort on the clientside. If you have more than 100 records, you have to paginate through them (or make several cursored queries in the same GraphQL call) and then combine and sort them clientside.
But it does kinda work and let you modify pageviews independent of Post revisions. It’s just a lot of work and a fair bit of mental complexity
Sorry about that!