Get metafield count on product under namespace

Highlighted
Tourist
7 0 1

Using GraphQL and the Shopify storefront API, there's no way of getting the number of metafields under a namespace for a given product.

I don't understand why this method would only be under the admin API, and not available in GraphQL.

 

It would be great to be able to run a query such as:

 

{
  products(first: 10) {
    edges {
      node {
        metafields(namespace: "reviews") {
          count
        }
      }
    }
  }
}

 

But unfortunately there is no field of count available.

0 Likes
Highlighted
Shopify Expert
4270 32 435

Probably because the front-end is meant to be a fast support mechanism for getting data, and not for analytic use of said data. In thinking about it, if you know your namespace, it means you know your metafields. In other words, you should know how many to expect in the namespace. So why is a count needed? If you do need to go through a namespace thoroughly because you know it exists, but you have no idea how much stuff exists there, then yes, paging is your only solution.

So even if you got a count, you still have to page, so having a count is not terribly helpful. It kinda sucks that you are stuck with a primitive review system that might just be writing a new metafield entry per review in a namespace. That is dumb because you can store a large JSON structure in a key, meaning you could store a large X number of reviews in one single metafield.

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Tourist
7 0 1

I need to know the total number of metafield reviews so I can show a summary of "This product has 1000 reviews".

It doesn't make sense to store all the reviews in a giant json metafield... that would be so slow to read and not scalable. I will paginate when I show the reviews individually, but I want a summary of the number of reviews. I don't want to store an entirely new metafield which is "reviewsCount" because it could go out of sync with the real number of reviews.

The API for getting the count of reviews exists under the admin API, my point is that it is not private information and I think should be moved to the storefront API.

0 Likes
Highlighted
Shopify Expert
4270 32 435

So make an API call the backend and get your precious count. One call won't hurt you. Secondly, while you are correct that storing reviews in JSON structures that could become large is a thing, you have zero evidence that would be slow and hard to scale. It is dumb simple Javascript to chew through and produce output, probably faster than your API intensive GQL calls. Prove it with benchmarks, I will concede. Otherwise, it's piffle.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Tourist
7 0 1

I don't get where your attitude comes from. I'm asking a question and didn't expect sarcasm from a "Shopify Expert".

I'm well aware that I can make a backend API for it to get my    " precious count "    ... but it requires me to make multiple calls to fetch just the count when it can easily be fetched within the same products query.

I'm not going to prove jack HunkyBill, I didn't make a question to provide proof... I didn't even object to the idea of making a backend API which fetches the count. I think you're piffle and I don't appreciate your lack of help. You literally contributed nothing so please let someone else make a contribution.

Thanks HunkyBill.

Highlighted
Shopify Expert
4270 32 435

One call to get a count, why more than one? As for my attitude, right back at you is some advice to not make blanket sweeping disparaging comments like "Does not scale", when really, that is not helpful either, since you have no clue if that is remotely true or not. Since you failed in the first place to articulate what you "are well aware of", I took it upon myself to try and steer you with 2 solutions, whereas you seem fixated on maintaining the status quo for yourself, if only Shopify would do the right thing for you, and give you a number. Anyway, whatever... thin skinned, thick-skinned, we both have better things to do than beat this dead horse.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Tourist
7 0 1

It is not scalable simply because: As the number of reviews increases, the slower it is for customers to load the reviews (not paginatable) and the more quota will be used from my GQL query.

If you're unhappy with your life, Shopify forums is not the place to prey on people. Good luck with your future support HunkyBill. I look forward to not seeing your reply.

If you don't have anything to contribute to a question, next time don't try to answer because it wastes everyones time.

0 Likes
Highlighted
Shopify Expert
4270 32 435

You are quick with the shallow thinking about the problem, same as the folks that implemented the crappy review system that uses metafields so poorly. I need no luck Ari9.

You have the privilege to not read my reply, nor to comment back, but you also have zero privilege to tell me what I can and cannot do with regards to these public forums. Happy to see you here asking questions, please do get comfortable with the world at large and not just the speck at the end of your nose.

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Shopify Staff
Shopify Staff
7 1 2

So, the main issue here is the usage of the Storefront API. As that API has a different set of access scopes than Admin API, we require an additional step to expose product metafields to it. There's a tutorial for it.

Because of that, there might be metafields under the namespace that aren't exposed to the Storefront API. As such, support for count doesn't make sense.

Highlighted
Shopify Expert
4270 32 435

So by this explanation, simply put, if you have a namespace "reviews", and perhaps 1000 reviews saved in that namespace, you also have to have added a visibility record to each and every review with the review's key? Wow... so when this primitive review system adds a single new review to the namespace, it also has to create the permission for Storefront API to read it. Interesting.

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes