Query referencedBy in MetaObject type, from Hydrogen storefront

Topic summary

Issue: In a Hydrogen (custom storefront) setup hosted on Oxygen, a Merchant metaobject is referenced by products. Fetching the metaobject from Product works, but fetching the reverse—products that reference a given metaobject via the referencedBy connection—fails or is unclear.

Key updates:

  • One user’s initial query using fields like name, namespace, target under referencedBy returned an internal error.
  • A revised query works when using referencedBy → edges → node → referencer and selecting Product fields (id, title, featuredImage). This suggests the correct field is referencer on the edge node.
  • Another user cannot use referencedBy at all and asks if additional scopes are needed for Hydrogen.
  • A participant notes the referencedBy connection is documented for the Admin GraphQL API, not the Storefront API, questioning whether successful examples are actually using Admin rather than Storefront.

Context: Hydrogen is Shopify’s React framework; Oxygen is hosting. Metaobjects are custom content types. referencedBy is intended to list resources (e.g., Products) that reference a metaobject.

Status: Unresolved. It’s unclear if referencedBy is supported in the Storefront API. The working example may rely on Admin API. Next steps: verify which API is in use, confirm permissions/scopes, or consider querying via Admin API or from the Product side.

Summarized with AI on December 26. AI used: gpt-5.

Hi all! I have a custom Storefront in Hydrogen, deployed in Oxygen.

I created a Merchant Metaobject in my shop to store some merchant data. Then I reference these Metaobjects in various Products, based on who merchandises those products.

**:white_check_mark: WORKING AS EXPECTED:**From the Product Entity in GraphQL, I can reference the Metaobject correctly and display the merchant data in the Product Details Page or Product Card.

:cross_mark: NOT WORKING AS EXPECTED: I have also created a Merchant page, and from the Metaobject in GraphQL I can query all the fields, BUT I can’t query the referencedBy connection, where I want to query all the Products where this Metaobject is referenced at.

How can I get this kind of information in the Metaobject payload?

Thank you! :grin:

1 Like

Hi,

I have the same issue. Can you show us some samples on how to query the reference products?

I have this query but it is not working.

{
  metaobjects(type: "test", first: 2) {
    nodes {
      id
      displayName
      referencedBy(first: 2) {
        edges {
          node {
            name
            namespace
            target {
              ... on Product {
                id
              }
            }
          }
        }
      }
    }
  }

This is the message response.

Internal error. Looks like something went wrong on our end.

I think I am using a wrong field. This query is working for me. Hope this helps.

{
  metaobjects(type: "test", first: 25) {
    nodes {
      id
      displayName
      referencedBy(first: 25) {
        edges {
          node {
            referencer {
              ... on Product {
                id
                title
              	featuredImage {
                  url(transform:{maxWidth:100})
                }
              }
            }
          }
        }
      }
    }
  }
}

Im having the same issue, but I cant use the “referencedBy” syntax. I can read about it in the docs. Do i need to change my access scope for hydrogen or something? Thanks

Where did you see it in the docs ? I just find it for Admin API here only:

https://shopify.dev/docs/api/admin-graphql/2024-07/objects/Metaobject#connection-referencedby

I guess there is no way how to do that with storefront, or might I be wrong?

Are you really using the storefront? Is this not Admin API?

1 Like