我正在使用GraphQL从Wordpress中的自定义ACF字段中提取信息到我的Gatsby站点。我的查询最初查询了三个ACF字段(ImageRow、TextRow和ImageTextRow),但是我随后删除了前两行,并将它们从查询中删除。那我呢。添加了一个名为HeroRow的新行,但是从那时起我就收到了这个错误:
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Fragment cannot be spread here as objects of type "WPGraphQL_Page_Customcontentblocks" can never be of
type "WPGraphQL_Page_Customcontentblocks_Customcontentblocks_HeroRow".
File: gatsby-node.js:82:28我的疑问如下:
query {
wpgraphql {
pages(first: 5000, where: {status : PUBLISH}){
nodes {
title
uri
status
content
customContentBlocks {
customcontentblocks {
... on WPGraphQL_Page_Customcontentblocks_Customcontentblocks_ImageTextRow {
fieldGroupName
version
imageV1 {
sourceUrl
}
titleV1
subtitleV1
textV1
linksV1 {
links {
target
title
url
}
}
imageV2 {
sourceUrl
}
titleV2
subtitleV2
textV2
listV2 {
listItem
}
ctaV2 {
target
title
url
}
}
}
... on WPGraphQL_Page_Customcontentblocks_Customcontentblocks_HeroRow {
fieldGroupName
title
image {
sourceUrl
}
links {
link {
target
title
url
}
}
}
}
}
}
}
}如果我单独查询ImageTextRow,我可以不出问题地查询它,但每当包含HeroRow时,我都会收到相同的错误消息。
我已经以与ImageTextRow布局相同的方式设置了我的HeroRow布局(两者都是同级的,都位于customContentBlocks字段组下),因此我希望查询对这两个字段都能起到相同的作用。
我还使用GraphiQL IDE在Wordpress端测试了查询,查询在Wordpress端运行得很好,问题似乎只是在Gatsby端。
发布于 2021-05-05 22:01:55
我设法解决了这个问题,但是我不完全确定为什么要解决这个问题:
通过改变查询中不同布局的顺序,使出错的布局(HeroRow)不是查询中的最后一个布局,一切工作正常:
query {
wpgraphql {
pages(first: 5000, where: {status : PUBLISH}){
nodes {
title
uri
status
content
customContentBlocks {
customcontentblocks {
... on WPGraphQL_Page_Customcontentblocks_Customcontentblocks_HeroRow {
fieldGroupName
title
image {
sourceUrl
}
links {
link {
target
title
url
}
}
}
... on WPGraphQL_Page_Customcontentblocks_Customcontentblocks_ImageTextRow {
fieldGroupName
version
imageV1 {
sourceUrl
}
titleV1
subtitleV1
textV1
linksV1 {
links {
target
title
url
}
}
imageV2 {
sourceUrl
}
titleV2
subtitleV2
textV2
listV2 {
listItem
}
ctaV2 {
target
title
url
}
}
}
}
}
}
}
}此后,我添加了多个后续行,一切都如预期的那样工作。
https://stackoverflow.com/questions/67212070
复制相似问题