Metafield Field Definition

Tento use all declared Shopify definitions, you can find all of them here

single_line_text_field

string
A single-line text field. String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.singleLineTextField(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.singleLineTextField({
  validations: (v) => [v.min(1)],
});
fieldDefinition: (f) => f.singleLineTextField({
  validations: (v) => [v.max(1)],
});
fieldDefinition: (f) => f.singleLineTextField({
  validations: (v) => [v.regex(".")],
});
  • Choices
    A list of up to 128 predefined options that limit the values allowed for the metafield.
fieldDefinition: (f) => f.singleLineTextField({
  validations: (v) => [v.choices(['choice1', 'choice2'])],
});

list.single_line_text_field

string[]
A list of single-line text fields.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.singleLineTextList(),
});

multi_line_text_field

string
A multi-line text field. String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.multiLineTextField(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.multiLineTextField({
  validations: (v) => [v.min(1)],
});
fieldDefinition: (f) => f.multiLineTextField({
  validations: (v) => [v.max(1)],
});
fieldDefinition: (f) => f.multiLineTextField({
  validations: (v) => [v.regex(".")],
});

---

number_decimal

string
A number with decimal places in the range of +/-9999999999999.999999999. String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.decimal(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.decimal({
  validations: (v) => [v.min(1)],
});
fieldDefinition: (f) => f.decimal({
  validations: (v) => [v.max(1)],
});
  • Maximum precision
    Sets the maximum number of decimal places to store for a decimal number
fieldDefinition: (f) => f.decimal({
  validations: (v) => [v.maxPrecision(1)],
});

list.number_decimal

string[]
A list of numbers with decimal places in the range of +/-9999999999999.999999999.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.decimalList(),
});

---

url

string
A URL with one of the allowed schemes: https, http, mailto, sms, tel. String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.url(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.url({
  validations: (v) => [v.allowedDomains("google.com")],
});

list.url

string[]
A list of URLs with one of the allowed schemes: https, http, mailto, sms, tel.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.urlList(),
});

---

number_integer

integer
A whole number in the range of +/-9,007,199,254,740,991.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.integer(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.integer({
  validations: (v) => [v.min(1)],
});
fieldDefinition: (f) => f.integer({
  validations: (v) => [v.max(1)],
});

list.number_integer

string[]
A list of whole numbers in the range of +/-9,007,199,254,740,991.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.integerList(),
});

---

date

string
A date in ISO 8601 format without a presumed timezone. String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.date(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.date({
  validations: (v) => [v.min("2024-01-01")],
});
// or
fieldDefinition: (f) => f.date({
  validations: (v) => [v.min(new Date("2024-01-01"))],
});
fieldDefinition: (f) => f.date({
  validations: (v) => [v.max("2024-01-01")],
});
// or
fieldDefinition: (f) => f.date({
  validations: (v) => [v.min(new Date("2024-01-01"))],
});

list.date

string[]
A list of dates in ISO 8601 format without a presumed timezone.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.dateList(),
});

---

date_time

string
A date and time in ISO 8601 format without a presumed timezone. Defaults to Greenwich Mean Time (GMT). String value types can store up to five million characters.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.dateTime(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.dateTime({
  validations: (v) => [v.min("2024-01-01")],
});
// or
fieldDefinition: (f) => f.dateTime({
  validations: (v) => [v.min(new Date("2024-01-01"))],
});
fieldDefinition: (f) => f.dateTime({
  validations: (v) => [v.max("2024-01-01")],
});
// or
fieldDefinition: (f) => f.dateTime({
  validations: (v) => [v.min(new Date("2024-01-01"))],
});

list.date_time

string[]
A list of dates and times in ISO 8601 format without a presumed timezone. Defaults to Greenwich Mean Time (GMT).

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.dateTimeList(),
});

---

dimension

json
A value and a unit of length. Valid unit values: in, ft, yd, mm, cm, m

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.dimension(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.dimension({
  validations: (v) => [v.min({
    value: 1,
    unit: "CENTIMETERS",
  })],
});
fieldDefinition: (f) => f.dimension({
  validations: (v) => [v.max({
    value: 1,
    unit: "CENTIMETERS",
  })],
});

list.dimension

json[]
A list of values and a unit of length. Valid unit values: in, ft, yd, mm, cm, m

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.dimensionList(),
});

---

volume

json
A value and a unit of volume. Valid unit values: ml, cl, l, m3 (cubic meters), us_fl_oz, us_pt, us_qt, us_gal, imp_fl_oz, imp_pt, imp_qt, imp_gal.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.volume(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.volume({
  validations: (v) => [v.min({
    value: 1,
    unit: "LITERS",
  })],
});
fieldDefinition: (f) => f.volume({
  validations: (v) => [v.max({
    value: 1,
    unit: "LITERS",
  })],
});

list.volume

json[]
A list of values and a unit of volume. Valid unit values: ml, cl, l, m3 (cubic meters), us_fl_oz, us_pt, us_qt, us_gal, imp_fl_oz, imp_pt, imp_qt, imp_gal.

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.volumeList(),
});

---

weight

json
A value and a unit of weight. Valid unit values: oz, lb, g, kg

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.weight(),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.weight({
  validations: (v) => [v.min({
    value: 1,
    unit: "KILOGRAMS",
  })],
});
fieldDefinition: (f) => f.weight({
  validations: (v) => [v.max({
    value: 1,
    unit: "KILOGRAMS",
  })],
});

list.weight

json[]
A list of values and a unit of weight. Valid unit values: oz, lb, g, kg

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.weightList(),
});

---

metaobject_reference

string
A reference to a metaobject entry. You can use validations to set which metaobject definition the metaobject must be.

export const metaobjectDefinition = metaobject({
  name: "Metaobject Definition",
  type: "metaobject_definition",
  fieldDefinitions: (f) => ({
    field: f.weight(),
  }),
});

export const metafieldDefinition = metafield({
  name: "Metafield Definition",
  key: "metafield_definition",
  namespace: "custom",
  ownerType: "PRODUCT",
  fieldDefinition: (f) => f.metaobjectReference({
    validations: (v) => [v.metaobjectDefinitionType(() => metaobjectDefinition.type)]
  }),
});

Validations

Custom validations that apply to values assigned to the field.

fieldDefinition: (f) => f.metaobjectReference({
  validations: (v) => [v.metaobjectDefinitionType(() => <metaobjectDefinition>.type)],
});