Managing Unreferenced Metaobjects: Need Bulk Cleanup Solution

We’ve run into an interesting challenge with metaobjects that I’m hoping someone can help with or share similar experiences.

The Situation:

  • Our app creates metaobjects for certain functionality
  • Initially, we were creating new instances each time without updating existing ones
  • We’ve fixed the creation bloat using metaobject upsert mutations (yay!)

The Problem:
We now have a lot of “orphaned” or unreferenced metaobjects from before we implemented the upsert solution. While they’re not causing immediate issues, they’re essentially dead weight in the store’s data.

What We Need:
A way to efficiently clean up these unreferenced metaobjects of a specific type.

Currently, we don’t see a straightforward way to:

  1. Identify which metaobjects are no longer referenced
  2. Bulk delete these unused metaobjects
  3. Clean up historical data without affecting current operations

Question:

  • Is there a recommended approach for handling this cleanup?

you have unreferenced metaobjects, or unreferenced metaobject entries?
If it’s entries, the admin list tells you which ones are not referenced, and you can select and delete from there.

Yes. I mean unreferenced metaobject entries.

There are few issues with that:

  • We have a lot of merchants for which we want to do this for. Preferably, looking for a solution that would help us achieve this programatically.
  • Our metaobject entires are not merchant writable, so we can’t delete them from the interface.

Hey @prakhar,

When you loop through metaobjects with the metaobjects query there’s a referencedBy attribute that returns a list of metafields that reference that metaobject. Could you retrieve the first reference, and, if it’s blank, delete the metaobject?

Here’s what the query to show the references would look like:

query ListMetaobjects {
  metaobjects(first: 10, type: "shopify--size") {
    edges {
      node {
        id
        type
        displayName
        updatedAt
        referencedBy (first: 1){
          edges {
            node {
              name
              key
            }
          }
        }
      }
    }
  }
}

Best,
Daniel

3 Likes

This looks like something that could work! Thanks, Daniel. Appreciate it.

1 Like