← back to Shopify Sample Shipping
disc-feasible.mjs
21 lines
import {query} from './query.mjs';
// 1) Existing free-shipping CODE discounts + their customerSelection type
try{
const codes=(await query(`{codeDiscountNodes(first:50){nodes{codeDiscount{__typename
... on DiscountCodeFreeShipping{title status appliesOnOneTimePurchase
customerSelection{__typename ... on DiscountCustomerSegments{segments{id name}} ... on DiscountCustomerAll{allCustomers}}
minimumRequirement{__typename ... on DiscountMinimumSubtotal{greaterThanOrEqualToSubtotal{amount}} ... on DiscountMinimumQuantity{greaterThanOrEqualToQuantity}}
maximumShippingPrice{amount}}}}}}`)).codeDiscountNodes.nodes;
const fsd=codes.filter(n=>n.codeDiscount?.__typename==='DiscountCodeFreeShipping');
console.log('=== FREE-SHIPPING CODE DISCOUNTS ('+fsd.length+') ===');
for(const n of fsd){const d=n.codeDiscount;console.log(`• ${d.title} [${d.status}] sel=${d.customerSelection?.__typename} min=${d.minimumRequirement?.__typename||'none'} maxShip=${d.maximumShippingPrice?.amount||'—'}`);
if(d.customerSelection?.segments)for(const s of d.customerSelection.segments)console.log(` seg: ${s.name}`);}
}catch(e){console.log('code err:',e.message);}
// 2) Confirm the discount schema SUPPORTS segment-scoped free shipping (introspect input)
try{
const t=(await query(`{__type(name:"DiscountCustomerSegments"){name kind fields{name}}}`)).__type;
console.log('\n=== DiscountCustomerSegments type exists? ===', t? 'YES ('+t.fields.map(f=>f.name).join(',')+')':'NO');
const t2=(await query(`{__type(name:"DiscountAutomaticFreeShipping"){name fields{name}}}`)).__type;
console.log('DiscountAutomaticFreeShipping fields:', t2? t2.fields.map(f=>f.name).join(','):'n/a');
}catch(e){console.log('introspect err:',e.message);}