I’m developing an app that is a product picker that adds complimentary products to the cart.
We have a series of metaobjects that are essentially definitions of different combinations of SKUs. There are around 5000 records stored in the metaobjects and I then have a search field in the app extension that does a metaobjects query.
I’m trying to query on the value of a field and return a valid list of these product definitions. I’m getting conflicting information from both Google Searches and various parts of the documentation about whether I can search based on a field value.
Because there are 5000 definitions it’s obviously not efficient to query them all each time and then sort through them programmatically to find the results I want.
Reading this. Query by metafield value suggests that I can turn on filtering for that field, but I also can’t work out how to make that change in metaobjectdefinitionupdate, I can’t see a reference to that field.
Is there something I’m missing
Please help, I’m tearing out my hair.
Search query code is below and I’ve attached a screenshot of the metaobject field definition.
async searchMachines(query, tableType) {
console.log('Searching for machines:', query, tableType);
tableType = "grande";
try {
const response = await this.admin.graphql(`
query SearchMachines($query: String!) {
metaobjects(
type: "app--228414980097--machine_compatibility"
first: 10
query: $query
) {
edges {
node {
id
fields {
key
value
reference {
... on Product {
id
title
handle
}
}
}
}
}
}
}
`, {
variables: {
query: `fields.table_type:"${tableType}" AND (fields.brand:"${query}" OR fields.model:"${query}" OR fields.model_number:"${query}" OR fields.prefix:"${query}" OR fields.suffix:"${query}")`
}
});