【发布时间】:2019-09-25 14:48:56
【问题描述】:
我想将文档中的 images 字段设置为 [SanityImage] 类型的数组。
我尝试将其设置为type: 'image',但是当我查询该字段时,我得到类型是[SanityCollectionItemsImages]
images 字段位于对象 (productVariant) 中,然后包含在主文档 (collection) 中,其中我的 items 字段中有一个 productVariants 数组。
在我的collection 文档的 fields 数组中:
...
{
title: "Items",
name: "items",
type: "array",
of: [
{
title: "Item",
type: "productVariant",
},
],
},
...
productVariant 类型对象:
export default {
title: "Product variant",
name: "productVariant",
type: "object",
fields: [
{
name: "images",
title: "Images",
type: "array",
of: [
{
type: "image",
options: {
hotspot: true,
},
},
],
},
...
我使用 GraphQL 的查询:
allSanityCollection {
edges {
node {
_id
title
description
items {
_key
title
images {
asset {
_ref
_id
fluid(maxHeight: 600) {
base64
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
}
}
}
}
}
}
}
当我单击 GraphiQL Web IDE 中的 images 字段时:
使用 Sanity.io HTTP API 获取整个文档:
"images": [
{
"_key": "5605f5383975",
"_type": "image",
"asset": {
"_ref": "image-14f9b7688912499f187b7c20e57816b3cdf42c1e-4016x4688-jpg",
"_type": "reference"
}
},
...
我的问题是如何将架构中字段的类型明确设置为 [SanityImage] 而不是 [SanityCollectionItemsImages],为什么我会得到那种奇怪的类型?
【问题讨论】:
-
这个你搞定了吗?
-
很遗憾没有。我也在他们的理智的松弛频道中问过,但没有运气。我切换到棱镜,一切看起来都更简单了