//native
export type DynSelect_type = string
export async function type(auth: RT.Shopify) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query { metaobjectDefinitions(first: 250) { nodes { type name } } }`,
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.metaobjectDefinitions.nodes.map(
(d: { type: string; name: string }) => ({
value: d.type,
label: `${d.name} (${d.type})`,
})
)
}
/**
* List Metaobjects
* List the metaobjects (entries) of one metaobject definition, with their fields. query filters with Shopify's search syntax (e.g. `display_name:Summer*`, `handle:my-entry`, `updated_at:>2026-01-01`; `fields.<key>:value` only works on fields marked admin-filterable). New entries take a few seconds to become searchable. Returns one page; pass pageInfo.endCursor as after for the next. Needs the read_metaobjects scope.
*/
export async function main(
auth: RT.Shopify,
type: DynSelect_type,
query: string | undefined,
sort_key: "updated_at" | "display_name" | "id" | "type" | undefined,
reverse: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query ($type: String!, $first: Int!, $after: String, $query: String, $sortKey: String, $reverse: Boolean) { metaobjects(type: $type, first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) { nodes { id handle type displayName updatedAt capabilities { publishable { status } } fields { key type value } } pageInfo { hasNextPage endCursor } } }`,
variables: {
type,
first: first || 50,
after: after || undefined,
query: query || undefined,
sortKey: sort_key || undefined,
reverse: reverse || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.metaobjects
}
Submitted by hugo989 3 hours ago