Shopify app development

From findscripter/everything-skills · View interactive version

Shopify app development is an AI agent skill from the GitHub repository findscripter/everything-skills. 当用 Shopify CLI 开发应用/扩展/主题,调用 GraphQL Admin API,配置 OAuth、Webhook、计费、访问域、metafield 或 Shopify Functions 时使用;做脚手架搭建、GraphQL 查询/变更、Liquid 模板与扩展编码并落地可部署产物;不适用于通用电商建站、非 Shopify 平台或纯运营配置(无代码改动);触发词:Shopify、shopify app、GraphQL Admin、Liquid、checkout extension、metafield、webhook、Polaris。

How to use this skill

Skill file

何时使用

先做路由判断(选错产物会全程返工):

不该用的边界:

步骤 / 指令

1. 路由:按上面四类判断要建 App / Extension / Theme / 组合。
2. 装 CLI 并初始化项目(见示例)。
3. 在 shopify.app.toml 配 access_scopes,遵循最小权限。
4. 写 GraphQL 查询/变更:只取所需字段,游标分页,>250 条用 bulk operations。
5. 扩展/主题编码:扩展用 @shopify/ui-extensions-react;主题用 Liquid section/snippet。
6. 配 Webhook(含 GDPR 三件套)并校验 HMAC 签名。
7. shopify app dev 本地联调(带隧道);shopify app deploy 发布扩展。
8. 提交前确认 API 版本(季度发布,12 个月弃用窗口),用 GraphiQL 验证 schema。

规则:

示例

安装与脚手架(CLI):

npm install -g @shopify/cli@latest
shopify app init          # 新建 app
shopify app dev           # 启动带隧道的开发服务器
shopify app deploy        # 构建并上传扩展到 Shopify

# 生成扩展
shopify app generate extension --type checkout_ui_extension
shopify app generate extension --type admin_action
shopify app generate extension --type function

# 主题
shopify theme init
shopify theme dev         # 本地预览 localhost:9292
shopify theme push --development

访问域(shopify.app.toml):

[access_scopes]
scopes = "read_products,write_products,read_orders,write_orders,read_customers"

GraphQL 查询商品(含游标分页):

query GetProducts($first: Int!, $query: String) {
  products(first: $first, query: $query) {
    edges {
      node { id title handle status
        variants(first: 5) { edges { node { id price inventoryQuantity } } }
      }
    }
    pageInfo { hasNextPage endCursor }
  }
}

写 metafield(变更 + 变量):

mutation SetMetafields($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields { id namespace key value }
    userErrors { field message }
  }
}
{ "metafields": [ {
  "ownerId": "gid://shopify/Product/123",
  "namespace": "custom", "key": "care_instructions",
  "value": "Handle with care", "type": "single_line_text_field"
} ] }

Checkout 扩展(React,礼品留言):

import { reactExtension, BlockStack, TextField, Checkbox,
  useApplyAttributeChange } from "@shopify/ui-extensions-react/checkout";

export default reactExtension("purchase.checkout.block.render", () => <GiftMessage />);

function GiftMessage() {
  const [isGift, setIsGift] = useState(false);
  const [message, setMessage] = useState("");
  const applyAttributeChange = useApplyAttributeChange();
  useEffect(() => {
    if (isGift && message)
      applyAttributeChange({ type: "updateAttribute", key: "gift_message", value: message });
  }, [isGift, message]);
  return (
    <BlockStack spacing="loose">
      <Checkbox checked={isGift} onChange={setIsGift}>This is a gift</Checkbox>
      {isGift && <TextField label="Gift Message" value={message} onChange={setMessage} multiline={3} />}
    </BlockStack>
  );
}

Liquid 商品卡 snippet:

<div class="product-card">
  <a href="{{ product.url }}">
    {% if product.featured_image %}
      <img src="{{ product.featured_image | img_url: 'medium' }}"
           alt="{{ product.title | escape }}" loading="lazy">
    {% endif %}
    <h3>{{ product.title }}</h3>
    <p class="price">{{ product.price | money }}</p>
    {% if product.compare_at_price > product.price %}<p class="sale-badge">Sale</p>{% endif %}
  </a>
</div>

Webhook(shopify.app.toml,含 GDPR 强制项,过审必备):

[webhooks]
api_version = "2026-01"

[[webhooks.subscriptions]]
topics = ["orders/create", "orders/updated"]
uri = "/webhooks/orders"

[webhooks.privacy_compliance]
customer_data_request_url = "/webhooks/gdpr/data-request"
customer_deletion_url = "/webhooks/gdpr/customer-deletion"
shop_deletion_url = "/webhooks/gdpr/shop-deletion"

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT),适配重写为中文「技能大典」条目。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.