Skip to main content

Metafield references added to Customer Account API

We have added metafield.reference and metafield.references to the Customer Account API. This means that reference Media types, including MediaImage, GenericFile, Model3d, and Video, now exist on the common query objects that currently support metafields on the Customer Account API.

Metaobjects can now also be queried through metafield.reference on the Customer Account API. To enable access to metaobjects, toggle the Customer Account API access toggle when editing a metaobject definition in Admin. After toggling this value on, metaobjects are exposed and accessible to apps with the customer_read_metaobjects scope.

This functionality can also be achieved with new changes to the GraphQL Admin API. We have exposed the ability to create, update, and query CustomerAccess, which can be set to either READ or NONE. You can specify the access on the MetaobjectAccess object when running the metaobjectDefinitionCreate or metaobjectDefinitionUpdate mutation.

Below are some example queries of Media types and metaobjects.

  1. Querying a Media object metafield.reference (MediaImage) through customer:
query {
customer {
metafield(namespace: "custom", key: "example") {
namespace
key
jsonValue
reference {
__typename
... on MediaImage {
image {
url
}
}
}
}
}
}
2. Querying a metaobject metafield.reference through an order (note, the metaobject contains a MediaImage reference):
order(id: "gid://shopify/Order/1") {
metafield(namespace: "custom", key: "example") {
__typename
namespace
key
reference {
__typename
... on Metaobject {
id
fields {
type
value
key
value
reference {
__typename
... on MediaImage {
id
image {
altText
url
}
}
}
}
}
}
}
}
Was this section helpful?