Metafield query filter returns all orders when no order has the metafield

I’m experiencing unexpected behavior when filtering orders using metafield queries.

My metafield configuration:

[order.metafields.app.is_b2b]
type = "boolean"
name = "Is B2B"
description = "Whether the order is a B2B order"
capabilities.admin_filterable = true

Issue:
When using query: metafields.$app.is_b2b:true to filter orders, the API returns all orders if no order in the store has this metafield set. However, once at least one order has the is_b2b metafield, the query correctly returns only orders with is_b2b:true.

Query Example:

query OrdersWithIsB2B {
  orders(first: 10, query: "metafields.$app.is_b2b:true") {
    edges {
      node {
        id
        name
        isB2B: metafield(namespace: "$app", key: "is_b2b") {
          value
        }
      }
    }
  }
}

Expected Behavior:

  • Returns empty array when no order has the metafield
  • Returns only orders with is_b2b:true when querying

Actual Behavior:

  • Returns all orders when no order has the metafield (even orders without the metafield)
  • Returns correctly filtered orders once at least one order has the metafield

Is this expected behavior or a bug?

Hi @shaheem

Indeed, I have also encountered this situation. @KyleG-Shopify Could you please clarify this matter?

1 Like

Take a look at this one to see if this is a similar situation as yours, along with the expected outcome.

Thanks, this seems very similar to what I’m seeing as well.

To clarify my scenario:

  • I added the order metafield definition in the app configuration and deployed it.
  • I then queried using metafields.$app.is_b2b:true before any order actually had this metafield set → the API returned all orders (I expected no orders).
  • After setting is_b2b = true on one order → the same query returned only that order (as expected).

As a temporary workaround, I’ve added an additional check to ensure the returned orders actually contain this metafield before treating them as valid matches.

That said, this still feels like unexpected behavior. I was under the impression that deploying an app-owned metafield definition would make the namespace/key available for filtering across any store with the app installed, even before any values exist.

@shaheem, I tried reproducing this with the TOML configuration but are not seeing the same behavior. Could you message me your shop so I could take a look at the logs to see if I can tell what might be happening?