GraphQL,Shopify 获取所有产品或产品总数
GraphQL, Shopify Get All products or totalcount of products
我是 graphQL 的新手,我必须检索所有产品。我一直在环顾四周,观看教程和阅读,人们似乎 return 他们想要的所有特定类型的数据,但我做不到。例如,它会抛出一个错误,说你必须提供第一个或最后一个,但我想要它们,否则它会说 totalCount 或计数不存在。
{
products {
id
title
price
}
}
// or get total count of products
{
products {
totalCount
}
}
我基本上是在尝试做类似的事情。我知道我可能得不到任何帮助,因为没有人可以访问我的 shopify 管理员 api,但甚至可能是一个例子或我能看到的任何东西。这是来自我的产品选项的 graphQL 查询根。
产品列表。
ProductConnection!
first: Int
Returns up to the first n elements from the list.
after: String
Returns the elements that come after the specified cursor.
last: Int
Returns up to the last n elements from the list.
before: String
Returns the elements that come before the specified cursor.
reverse: Boolean = false
Reverse the order of the underlying list.
sortKey: ProductSortKeys = ID
Sort the underlying list by the given key.
query: String
Supported filter parameters:
barcode
created_at
delivery_profile_id
error_feedback
gift_card
inventory_total
is_price_reduced
out_of_stock_somewhere
price
product_type
publishable_status
published_status
sku
status
tag
title
updated_at
vendor
See the detailed search syntax for more information about using filters.
savedSearchId: ID
ID of an existing saved search. The search’s query string is used as the query argument.
您无法通过使用 StoreFront GraphQL 或 Admin GraphQL 的单个 GraphQL 请求获取所有产品。
如果您的产品少于 250 个,您可以使用 first: 250
发出请求,但如果您的产品超过 250 个,则需要使用 GraphQL 的游标分页进行递归请求。因此,如果您有 1000 种产品,则需要提出 4 个请求(取决于您使用的 API,店面或管理员 graphql api,因为它们不同)
目前无法通过 Shopify 提供的任何 API 使用单个请求获取所有产品。
实现此目的的唯一方法是使用以下代码制作自定义模板:
[
{% paginate collection.products by 9999 %}
{% for product in collection.products %}
{{product | json}}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% endpagination %}
]
将其命名为 collection.ajax.liquid
。
并使用视图参数向其发出获取请求:
fetch('/collections/all?view=ajax').then((response) => handle the response)
请记住,您拥有的产品越多,对该页面的请求时间就越长。如果您有 1000 件产品,请求最多可能需要 10 秒。因此,对于大量产品来说,这也不是一个很好的解决方案。
至于总计数,有一个液体对象 {{ collection.all_products_count }}
或者如果您正在做管理工作,请使用其余的 api,因为有一种方法可以获取产品计数,但是 graphql 中有 none。
GraphQL 的新手,但据我了解,边表示与节点相关的信息。
与您在关系 ManyToMany
关系中所做的非常相似,能够添加额外的列,其中包含有关两个记录之间的关系的信息,但不存储在任何这些记录中。
例如:一个用户喜欢一个Post,就是属于关系的信息。
摘自文档:
The concept of an edge also proves useful if there is information that is specific to the edge, rather than to one of the objects. For example, if we wanted to expose "friendship time" in the API, having it live on the edge is a natural place to put it.
https://graphql.org/learn/pagination/
您可以使用 BULK API 并结合 GRAPHQL
获取所有产品
我是 graphQL 的新手,我必须检索所有产品。我一直在环顾四周,观看教程和阅读,人们似乎 return 他们想要的所有特定类型的数据,但我做不到。例如,它会抛出一个错误,说你必须提供第一个或最后一个,但我想要它们,否则它会说 totalCount 或计数不存在。
{
products {
id
title
price
}
}
// or get total count of products
{
products {
totalCount
}
}
我基本上是在尝试做类似的事情。我知道我可能得不到任何帮助,因为没有人可以访问我的 shopify 管理员 api,但甚至可能是一个例子或我能看到的任何东西。这是来自我的产品选项的 graphQL 查询根。 产品列表。
ProductConnection!
first: Int
Returns up to the first n elements from the list.
after: String
Returns the elements that come after the specified cursor.
last: Int
Returns up to the last n elements from the list.
before: String
Returns the elements that come before the specified cursor.
reverse: Boolean = false
Reverse the order of the underlying list.
sortKey: ProductSortKeys = ID
Sort the underlying list by the given key.
query: String
Supported filter parameters:
barcode
created_at
delivery_profile_id
error_feedback
gift_card
inventory_total
is_price_reduced
out_of_stock_somewhere
price
product_type
publishable_status
published_status
sku
status
tag
title
updated_at
vendor
See the detailed search syntax for more information about using filters.
savedSearchId: ID
ID of an existing saved search. The search’s query string is used as the query argument.
您无法通过使用 StoreFront GraphQL 或 Admin GraphQL 的单个 GraphQL 请求获取所有产品。
如果您的产品少于 250 个,您可以使用 first: 250
发出请求,但如果您的产品超过 250 个,则需要使用 GraphQL 的游标分页进行递归请求。因此,如果您有 1000 种产品,则需要提出 4 个请求(取决于您使用的 API,店面或管理员 graphql api,因为它们不同)
目前无法通过 Shopify 提供的任何 API 使用单个请求获取所有产品。
实现此目的的唯一方法是使用以下代码制作自定义模板:
[
{% paginate collection.products by 9999 %}
{% for product in collection.products %}
{{product | json}}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% endpagination %}
]
将其命名为 collection.ajax.liquid
。
并使用视图参数向其发出获取请求:
fetch('/collections/all?view=ajax').then((response) => handle the response)
请记住,您拥有的产品越多,对该页面的请求时间就越长。如果您有 1000 件产品,请求最多可能需要 10 秒。因此,对于大量产品来说,这也不是一个很好的解决方案。
至于总计数,有一个液体对象 {{ collection.all_products_count }}
或者如果您正在做管理工作,请使用其余的 api,因为有一种方法可以获取产品计数,但是 graphql 中有 none。
GraphQL 的新手,但据我了解,边表示与节点相关的信息。
与您在关系 ManyToMany
关系中所做的非常相似,能够添加额外的列,其中包含有关两个记录之间的关系的信息,但不存储在任何这些记录中。
例如:一个用户喜欢一个Post,就是属于关系的信息。
摘自文档:
The concept of an edge also proves useful if there is information that is specific to the edge, rather than to one of the objects. For example, if we wanted to expose "friendship time" in the API, having it live on the edge is a natural place to put it. https://graphql.org/learn/pagination/
您可以使用 BULK API 并结合 GRAPHQL
获取所有产品