cli icon indicating copy to clipboard operation
cli copied to clipboard

[Feature]: Ability to query where metafields are populated within the CLI

Open rcasimmons opened this issue 9 months ago • 1 comments

What area(s) will this request affect?

Theme

What type of change do you want to see?

New feature

Overview

Within the Shopify Admin, we can obviously create metafields for different page types (i.e Product, Collections etc) and it will tell us how many are assigned/used with that metafield - the problem is, unlike say WordPress (or maybe Magento), we're unable to see where that has been populated.

What if I could have a tool, like the Liquid testing tool, where I can enter in a namespace and key and it'll return where that's populated?

Or alt. this is returned when metafields.json is pulled?

Motivation

Going back to the problem statement, Shopify doesn't enable us to directly see where that metafield is populated.

The motivation here is that, say the client hasn't really given us visibility on a problematic metafield or we're dealing with a LARGE list of collections, it would mean I'd have to spend a huge amount of time combing through each collection or product etc. to find where that metafield has been populated.

For example, say we have a 'Collection alt. description' metafield and the client is unable to tell us where (say they've forgotten) and it's only populated on 5 out of 200 collections, we'd need to essentially go through a good chunk before we can actually diagnose the problem.

The way I'm thinking is two methods - the first being the following:

  1. A developer runs shopify theme metafields query
  2. The CLI will then 'prompt' the user to enter in either the full reference or just the namespace and key - for example, it could be collections.metafields.custom.alt_description or custom.alt_description.
  3. It will then query and return a scrollable list within the CLI of what has been populated.

The second method would be to update metafields.json with a object of handles where this has been populated.

rcasimmons avatar Mar 14 '25 14:03 rcasimmons

The metafields file is more for tooling purposes. Is what you're looking for provided by the Metafield query through GraphQL API?

You could query the metafield, and it's associated references it is connected to. See docs

aswamy avatar Apr 24 '25 16:04 aswamy

The metafields file is more for tooling purposes. Is what you're looking for provided by the Metafield query through GraphQL API?

You could query the metafield, and it's associated references it is connected to. See docs

I'm on a new GitHub account due to the old one being related to my old company so I apologise.

This would work although do you have an example of useage? I'm incredibly novice when it comes to GraphQL as it's just not something we use in our stack as we've never needed to.

Wouldn't this require the GraphiQL App on each store in order to query it?

nbskubix avatar May 22 '25 10:05 nbskubix

You would generate your own Admin API token and then query the API yourself. Here's an example of a query I would use if I wanted to find all of the use cases of a custom metafield definition called "volume" that's for products:

query MetafieldDefinitionUsage {
  metafieldDefinition(
    identifier: {ownerType: PRODUCT, namespace: "custom", key: "volume"}
  ) {
    id
    metafields(first: 50) {
      edges {
        node {
          id
          jsonValue
          owner {
            ... on Product {
              id
              title
            }
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

That would let you see all of the values for each metafield as well as which product it's attached to. In it we're also request the pagination info so you can see if you need to request more metafields. You can learn more about pagination here: https://shopify.dev/docs/api/usage/pagination-graphql

I don't see us adding something like this to the theme command, though. I am, however, reaching out to the appropriate team about beefing up the Admin so that you can see the connections there.

graygilmore avatar Jun 24 '25 22:06 graygilmore