Hello,
I have a question regarding the declarative data definitions. It says that it will keep in sync the schema. However, what happens if we explicitly add custom fields (for instance to customize the definition on a per-store basis). Will Shopify automatically remove any fields if they are not in the TOML file?
1 Like
Hi!
Metaobject definitions you manage via the TOML/App configuration cannot be edited via the API – they’re locked in sync across all shops. If you try to edit the metaobject definition via the API to add additional fields, you’ll get an error message.
So, you could include all the fields you might use in your declared definition (and with app scoped limits this is easier than before). Or, you could continue to manage specific definitions from the API.
The API is still very much an option and you are welcome to have some declared and some “dynamic” definitions within a single app – you don’t have to commit to one model and you don’t have to migrate everything at once.
Do you mind me asking what prompted the question – what’s the use-case you had in mind?
1 Like
Thanks for the answer. The use case is that I’m trying to create a store locator. Each store has a common set of properties (name, address…). The merchant can also dynamically add custom fields (so this can’t be hardcoded) such as “has WiFi”, “has terrace”, “food offering…”. It would have been extremely useful to be able to alter a definition via the API.
You could explore something like this:
[metaobjects.app.store]
access.admin = "merchant_read_write"
[metaobjects.app.store.fields]
name = "single_line_text_field"
address = "single_line_text_field"
[metaobjects.app.custom_store_properties]
access.admin = "merchant_read_write"
[metaobjects.app.custom_store_properties.fields]
store = "metaobject_reference<$app:store>"
property_name = "single_line_text_field"
value = "single_line_text_field"
But whether that’s a good fit for you I think would depend on your access patterns.
Wanting to take a declarative base and extend it in different places is an interesting idea.
1 Like
Yes, this approach won’t make it unfortunately. I don’t know in advance the type of the custom fields that need to be added, it’s really on a merchant by merchant basis based on their needs. I think one simple approach would be to allow editing the declarative definitions, and add a “declarative” new Boolean attribute on field. When altering a definition, those custom fields would have a declarative to true, and those would be excluded from the sync logic.