← back to Shopify Sample Shipping

ptype-distinct.mjs

14 lines

import {query} from './query.mjs';
// Sample a range of products to learn the real product.type vocabulary + sample-variant shape
const q=`{products(first:60, query:"status:active"){nodes{productType title
  variants(first:3){nodes{title sku}}}}}`;
const d=await query(q);
const types={};
let sampleShapes=new Set();
for(const p of d.products.nodes){
  types[p.productType||'(empty)']=(types[p.productType||'(empty)']||0)+1;
  for(const v of p.variants.nodes){ if(/sample/i.test(v.title)||/-sample$/i.test(v.sku||'')) sampleShapes.add(`title="${v.title}" sku~="${(v.sku||'').replace(/[0-9]+/g,'#')}"`); }
}
console.log('PRODUCT TYPES (60 active products):'); Object.entries(types).sort((a,b)=>b[1]-a[1]).forEach(([t,n])=>console.log(`  ${String(n).padStart(3)}  "${t}"`));
console.log('\nSAMPLE VARIANT SHAPES seen:'); [...sampleShapes].forEach(s=>console.log('  '+s));