← back to Dw Sarah Rowland Searchfix

create-def.mjs

16 lines

import { gql } from './lib.mjs';
const M = `mutation{
  metafieldDefinitionCreate(definition:{
    name:"Designer", namespace:"custom", key:"designer",
    ownerType:PRODUCT, type:"single_line_text_field",
    description:"Named designer/design line for this product (search + merchandising)"
  }){
    createdDefinition{ id name }
    userErrors{ field message code }
  }
}`;
const d = await gql(M);
const r = d.metafieldDefinitionCreate;
if (r.userErrors.length) console.log('userErrors:', JSON.stringify(r.userErrors));
console.log('created:', r.createdDefinition ? r.createdDefinition.id : '(none — may already exist)');