首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphQLError:片段不能在这里展开,因为"foo“类型的对象永远不能是"bar”类型。

GraphQLError:片段不能在这里展开,因为"foo“类型的对象永远不能是"bar”类型。
EN

Stack Overflow用户
提问于 2021-04-22 19:09:38
回答 1查看 128关注 0票数 1

我正在使用GraphQL从Wordpress中的自定义ACF字段中提取信息到我的Gatsby站点。我的查询最初查询了三个ACF字段(ImageRow、TextRow和ImageTextRow),但是我随后删除了前两行,并将它们从查询中删除。那我呢。添加了一个名为HeroRow的新行,但是从那时起我就收到了这个错误:

代码语言:javascript
复制
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

我的疑问如下:

代码语言:javascript
复制
    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端。

EN

回答 1

Stack Overflow用户

发布于 2021-05-05 22:01:55

我设法解决了这个问题,但是我不完全确定为什么要解决这个问题:

通过改变查询中不同布局的顺序,使出错的布局(HeroRow)不是查询中的最后一个布局,一切工作正常:

代码语言:javascript
复制
    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
                            }
                          }
                        }
                    }
                }
            }
        }
    }

此后,我添加了多个后续行,一切都如预期的那样工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67212070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档