【发布时间】:2020-06-26 05:06:54
【问题描述】:
我正在尝试为 Strapi 创建一个可创建/编辑动态区域的突变。 Strapi 中的动态区域是联合类型。如何使用 动态区域 进行 GraphQL mutation?
确切地说。这里应该是什么内容?
输入:{data: {inhalt: [{text: "hallo"}]}}
在下面的示例中,有一个名为 impressum 的组件。 Inhalt 是动态区域。它包含不同的组件:ComponentPageText、ComponentPageInformation 和 ComponentPageArticle。
这个突变
mutation {
updateImpressum(input: {data: {inhalt: [{text: "hallo"}]}}) {
impressum {
inhalt {
__typename
}
}
}
}
返回
预期类型 ImpressumInhaltDynamicZoneInput!,找到 {text: \"hallo\"};未找到组件。预期之一:ComponentPageText、ComponentPageInformation、ComponentPageArticle
这会返回同样的错误
mutation {
updateImpressum(input: {data: {inhalt: [{ComponentPageText: {text: "hallo"}}]}}) {
impressum {
inhalt {
__typename
}
}
}
}
架构自省返回
{
"name": "ComponentPageText",
"kind": "OBJECT"
}
结构(在评论后添加)
impressum => inhalt => [page.text, page.information, page.article]
对应
单一类型 => 动态区域 => [组件]
组件中的字段
page.text:文本
page.information:标题、文本、图片
page.article:与集合类型 - 文章
架构自省
{
"name": "updateImpressum",
"__typename": "__Field",
"description": "",
"args": [
{
"name": "input",
"description": "",
"__typename": "__InputValue",
"type": {
"kind": "INPUT_OBJECT",
"name": "updateImpressumInput",
"possibleTypes": null,
"interfaces": null,
"inputFields": [
{
"name": "data",
"description": "",
"__typename": "__InputValue"
}
]
}
}
]
}
【问题讨论】:
-
您好,能否分享一下您的组合和内容类型结构。
-
@JimLAURIE 我在问题中添加了上面的结构。这是你的意思吗?您需要更多信息吗?