You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过Shopify Admin API按嵌套属性值查询订单?

Shopify Admin API 能否按嵌套属性值查询订单?

问题背景

我需要查询某客户的所有订单,但仅返回app.name值为“Online Store”的订单。通过非嵌套属性(如displayFulfillmentStatus)查询订单的操作很简单:

有效查询(非嵌套属性)

查询语句:

query ($displayFulfillmentStatus: String!) {
  customer(id: "gid://shopify/Customer/123123123") {
    orders(first: 10, query: $displayFulfillmentStatus) {
      edges {
        node {
          displayFulfillmentStatus
          app {
           name
          }
        }
      }
    }
  }
}

GraphQL变量:

{
  "displayFulfillmentStatus": "UNFULFILLED"
}

但尝试按app.name值查询时始终无法得到结果,我试过以下两种变量格式,也尝试过不定义变量直接写查询字符串,都没有效果:
变量格式1:

{
  "appName": "Online Store"
}

变量格式2:

{
  "app": {
    "name": "Online Store"
  }
}

想确认:这是否是一项无法实现的功能?Shopify是否支持按嵌套属性参数筛选订单?


结论

Shopify Admin API 不支持直接通过app.name这类嵌套属性筛选订单,原因在于customer.orders的query参数遵循的是Shopify自定义的订单搜索语法,而非标准GraphQL的嵌套字段过滤规则。

原因说明

你之前使用的displayFulfillmentStatus能生效,是因为这个变量对应的是Shopify订单搜索语法中的fulfillment_status:unfulfilled关键词——并非直接对应GraphQL字段。而app.name没有对应的搜索关键词,因此无法直接通过嵌套字段格式筛选。

可行解决方案

方案1:客户端筛选(简单直接)

先获取该客户的所有订单,再在本地筛选出app.name为“Online Store”的订单。注意订单数量较多时需处理分页逻辑:

查询语句:

query {
  customer(id: "gid://shopify/Customer/123123123") {
    orders(first: 100) {
      edges {
        node {
          id
          app {
            name
          }
          # 按需添加其他字段
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

获取所有订单后,在客户端代码中过滤(示例):

const filteredOrders = customer.orders.edges.filter(edge => 
  edge.node.app?.name === "Online Store"
);

方案2:通过App ID服务端筛选(更高效)

如果需要在服务端完成筛选,可以先查询到“Online Store”应用的ID,再用app_id关键词进行订单筛选:

  1. 查询应用ID:
query {
  apps(first: 10, query: "name:'Online Store'") {
    edges {
      node {
        id
        name
      }
    }
  }
}
  1. 用App ID筛选订单:
    将上一步得到的应用ID(格式如gid://shopify/App/xxxxxx)作为参数传入订单查询:
    查询语句:
query ($appIdQuery: String!) {
  customer(id: "gid://shopify/Customer/123123123") {
    orders(first: 10, query: $appIdQuery) {
      edges {
        node {
          id
          app {
            name
          }
        }
      }
    }
  }
}

变量:

{
  "appIdQuery": "app_id:gid://shopify/App/xxxxxx"
}

补充说明

Shopify的订单搜索语法支持的关键词基于其后台订单搜索栏规则,目前确实没有直接通过app.name筛选的选项,上述两种方案是当前的可行替代方式。

内容的提问来源于stack exchange,提问作者ra-11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 07:47:26