我有一个Post
内容类型,它有一个FeaturedImage
字段。因为这个字段是一个图像上传,所以Strapi生成了方便的附加格式:thumbnail
、small
、medium
和large
。
当我在JSON中查询所有帖子时,我在响应中得到了以下格式:
{
"id": 1,
"Title": "Hello World",
"Content": "Nullam id dolor id nibh ultricies vehicula ut id elit..",
"FeaturedImage": {
"id": 1,
"name": "angel-jimenez-168185",
"alternativeText": "",
"caption": "",
"width": 2768,
"height": 1560,
"formats": {
"thumbnail": {
"hash": "thumbnail_angel_jimenez_168185_aaceac7acf",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 245,
"height": 138,
"size": 6.22,
"path": null,
"url": "/uploads/thumbnail_angel_jimenez_168185_aaceac7acf.jpeg"
},
"large": {
"hash": "large_angel_jimenez_168185_aaceac7acf",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 1000,
"height": 564,
"size": 75.71,
"path": null,
"url": "/uploads/large_angel_jimenez_168185_aaceac7acf.jpeg"
},
"medium": {
"hash": "medium_angel_jimenez_168185_aaceac7acf",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 750,
"height": 423,
"size": 41.8,
"path": null,
"url": "/uploads/medium_angel_jimenez_168185_aaceac7acf.jpeg"
},
"small": {
"hash": "small_angel_jimenez_168185_aaceac7acf",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 500,
"height": 282,
"size": 19.69,
"path": null,
"url": "/uploads/small_angel_jimenez_168185_aaceac7acf.jpeg"
}
}
}
}
但是,如果我在GraphQL中查询,只有原始(全尺寸)图像的publicURL
可用:
如何使用GraphQL访问这些图像格式?
发布于 2020-08-16 12:44:57
这个查询向我显示了所有预期的格式对象:
query MyQuery {
strapi {
home {
content {
image {
formats
}
}
}
}
}
我确实在strapi https://strapi.io/documentation/3.0.0-beta.x/plugins/graphql.html#usage上显式安装了graphql插件
我在我的api中使用了/graphql (例如http://localhost:1337/graphql)。
我希望这会有帮助,@jgthms
仅供参考strapi v.3.1.4 strapi-plugin-graphql v.3.1.4
发布于 2020-07-02 13:52:46
我今天遇到了同样的问题,并且试图解决这个问题已经太久了。似乎问题是,当查询是“格式”是JSON类型,它不会让它被查询。我真的不确定为什么会发生这种情况,也不知道如何解决它。任何建议都会有所帮助。
https://stackoverflow.com/questions/62662953
复制相似问题