← back to Dw Sarah Rowland Searchfix
inspect-designer.mjs
27 lines
import { gql } from './lib.mjs';
// full definition list (paginated) + a live sample of the metafield on a real product
const Q = `
query($cursor:String){
metafieldDefinitions(first:250, ownerType:PRODUCT, namespace:"custom", after:$cursor){
pageInfo{ hasNextPage endCursor }
nodes{ key type{ name } }
}
}`;
let cursor=null, defs=[];
do { const d=await gql(Q,{cursor}); defs.push(...d.metafieldDefinitions.nodes);
cursor=d.metafieldDefinitions.pageInfo.hasNextPage?d.metafieldDefinitions.pageInfo.endCursor:null;
} while(cursor);
const des = defs.find(x=>x.key==='designer');
console.log('TOTAL custom defs:', defs.length);
console.log('custom.designer DEFINITION type:', des ? des.type.name : 'NONE');
// sample actual metafield instances on products in the collection
const S = `{
products(first:5, query:"tag:'Architectural Wallcoverings'"){
nodes{ title metafield(namespace:"custom",key:"designer"){ type value } }
}
}`;
const s = await gql(S);
console.log('\nSample custom.designer values on products:');
s.products.nodes.forEach(p=>console.log(` ${p.title.slice(0,40)} -> ${p.metafield?JSON.stringify(p.metafield):'null'}`));