片段"F1"不能在此散布为“节点"类型的对象.永远不能是"Store"类型 [英] Fragment "F1" cannot be spread here as objects of type "Node" can never be of type "Store"

查看:54
本文介绍了片段"F1"不能在此散布为“节点"类型的对象.永远不能是"Store"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面的代码:

在某些用户操作下,以下方法称为:

On Certain User Action below method is called :

handleFolderClicked = (topic, parent) => {
    console.log('Main : handleFolderClicked called : ', parent);
    this.props.relay.setVariables({
      parentFolder: parent,
      email: loginEmail
    });
  }

Main = Relay.createContainer(Main, {
  initialVariables: {
    pageSize: pageSize,
    email: loginEmail,
    parentFolder: parentFolder,
  },
  fragments: {
    store: () => Relay.QL`
      fragment on Store {
        id,
        fileConnection(first:999, email:$email, parentFolder:$parentFolder) {
          ${DirectoryListing.getFragment('files')},
        }
        users {
          email,
        }
      }
    `,
  }
});
export default Main;

在页面加载时,它可以正常工作并获取结果,但是当使用setVariables更改parentFolder的值时,它将抛出以上错误.

On the time of page load its working fine and fetching results but when value of parentFolder is changed using setVariables, it throws above error.

洞察力可能会有用并受到赞赏.谢谢

An insight might be useful and appreciated. Thanks

推荐答案

我遇到了此错误,并使用以下方法解决了该问题:

I had this error and I solved with something like this:

Store 必须实现Relay的 Node 接口,这意味着它必须提供 id:ID!字段,如果执行使用返回的ID进行节点查询,则必须返回您的 Store .

Store has to implement Relay's Node interface, meaning that it has to provide an id: ID! field, and if you do a node query using the returned ID, your Store has to be returned.

在我的情况下,我将根对象 viewer 命名为 Viewer 类型;因此,在实现 Node 接口之后,此查询必须起作用:

In my case I named my root object viewer of type Viewer; so after implementing the Node interface, this query has to work:

{
  viewer {
    id
  }
}

哪个返回:

{
  "data": {
    "viewer": {
      "id": "Vmlld2VyOk5vbmU="
    }
  }
}

现在,如果我使用该ID来运行节点查询,则必须返回查看器.因此对于查询:

Now if I use that ID to run a node Query, the viewer has to be returned. So for the query:

{
  node(id: "Vmlld2VyOk5vbmU=") {
    id,
    __typename
  }
}

这应该是结果:

{
  "data": {
    "node": {
      "id": "Vmlld2VyOk5vbmU=",
      "__typename": "Viewer"
    }
  }
}

将所有出现的 viewer / Viewer 替换为 store / Store ,它应该可以工作.

Replace all occurrences of viewer/Viewer with store/Store and it should work.

这篇关于片段"F1"不能在此散布为“节点"类型的对象.永远不能是"Store"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆