← back to Shopify Sample Shipping

ptype-check.mjs

13 lines

import {query} from './query.mjs';
const q=`query($c:String){products(first:250,after:$c,query:"variants.title:Sample"){pageInfo{hasNextPage endCursor} nodes{productType}}}`;
const freq=new Map(); let c=null,pages=0,total=0;
while(pages<12){
  const d=await query(q,{c}); pages++;
  for(const n of d.products.nodes){total++;const t=(n.productType||'(blank)');freq.set(t,(freq.get(t)||0)+1);}
  if(!d.products.pageInfo.hasNextPage)break; c=d.products.pageInfo.endCursor;
}
const all=[...freq.entries()].sort((a,b)=>b[1]-a[1]);
console.log(`sampled ${total} products with a Sample variant across ${pages} pages`);
console.log('=== productType distribution ===');
for(const [t,n] of all) console.log(`  ${String(n).padStart(5)}  ${t}`);