![](/img/trans.png)
[英]Why does "Clear Local Storage" not work in Fauna GraphQL Playground?
[英]Grapgql Playground Fauna - file not defined, but it is defined
嗨,我正在学习如何使用动物群作为电子商务应用程序的数据库。 这是第一次设置一些模式,我找不到如何执行此操作的示例。
我的架构:
type Image {
src: String!
alt: String!
}
type ArtworkEntry {
name: String!
category: String!
price: Int!
currency: String!
image: Image
}
这是我在动物群 graphql 操场上的 graphql 突变
mutation CreateArtworkEntry {
createArtworkEntry(data: {
name: "DDD"
category: "DDD"
price: 101
currency: "USD"
image: {
src: "https://www.pexels.com/photo/26938/"
alt: "https://www.pexels.com/photo/26938/"
}
}
) {
name
category
image
price
currency
}
}
按播放时出现以下错误:“字段'src'不是由类型'ArtworkEntryImageRelation'定义的。
请引导我走正确的道路(我确实用新保存的更改替换了架构)
在您的架构中, ArtworkEntry
类型中的image
字段表示该值是Image
类型。 但是,它没有说明应该如何发生。
由于ArtworkEntry
和Image
之间似乎存在一对一的关系,因此Image
类型应该包含@embedded
指令,如下所示:
type Image @embedded {
src: String!
alt: String!
}
使用@embedded
允许您将一种类型“嵌入”到另一种类型中,这样单个文档就会存在嵌套字段。
随着这种变化,你的突变也需要改变。 照原样,错误是:
{
"data": null,
"errors": [
{
"message": "Field 'image' of type 'Image' must have a sub selection. (line 7, column 5):\n image\n ^",
"locations": [
{
"line": 7,
"column": 5
}
]
}
]
}
要解决此问题,请更新您的突变以指定要在Image
类型中返回的字段:
mutation CreateArtworkEntry {
createArtworkEntry(data: {
name: "DDD"
category: "DDD"
price: 101
currency: "USD"
image: {
src: "https://www.pexels.com/photo/26938/"
alt: "https://www.pexels.com/photo/26938/"
}
}
) {
name
category
image {
src
alt
}
price
currency
}
}
然后结果是:
{
"data": {
"createArtworkEntry": {
"name": "DDD",
"category": "DDD",
"image": {
"src": "https://www.pexels.com/photo/26938/",
"alt": "https://www.pexels.com/photo/26938/"
},
"price": 101,
"currency": "USD"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.