【问题标题】:Attempted to add an ID already in GraphQLSegment已尝试在 GraphQLSegment 中添加 ID
【发布时间】:2016-11-21 11:52:04
【问题描述】:

我的 Relay/GraphQL 片段包含两个不同的查询,它们都返回相同类型的对象,并且它们返回的结果集之间经常有一些重叠(这对我来说完全没问题)。我在浏览器中看到以下警告:

Attempted to add an ID already in GraphQLSegment: client:client:15254944391:UmV2aWV3ZXI6MQ==
cra.dll.js:106483 Attempted to add noncontiguous index to GraphQLSegment: 52 to (0, 2)
cra.dll.js:106483 Attempted to add noncontiguous index to GraphQLSegment: 53 to (0, 2)
cra.dll.js:106483 Attempted to add noncontiguous index to GraphQLSegment: 54 to (0, 2)
cra.dll.js:106483 Attempted to add noncontiguous index to GraphQLSegment: 55 to (0, 2)

有人可以确认这确实是因为我两次看到同一个 Relay 对象吗?如何使警告静音或至少进一步调试?

【问题讨论】:

  • 您能同时找到解决此问题的方法吗?当我尝试获取名为User 的类型实体的详细信息时,我收到了同样的警告,每个实体都定义了Role 的列表(n 到 n 关系)。似乎加载Role 两次(访问两个具有相同分配角色的Users)会触发此警告。
  • @MichaelHilus,还没有,抱歉

标签: reactjs graphql relayjs


【解决方案1】:

不看代码就能知道,但您可能在您的类型 2x 上运行 nodeDefinition。如果您在顶级对象上定义了 globalIDField,如下所示:

let {nodeInterface, nodeField } = nodeDefinitions(
(globalId) => {
  let { type, id } = fromGlobalId(globalId)
  console.log('NodeDefinitions (globalId), id:', id)
  console.log('NodeDefinitions (globalId), type:', type)

  if (type === 'TopLevelObject') {
    return toplevelobject
  }
  return null
},
(obj) => {
  if (obj instanceof TopLevelObject) {
    return toplevelobjectType 
  } 
  return null 
}

)

那么你应该像这样引用任何其他对象:

让 itemType = new GraphQLObjectType({ 名称:'项目', 字段:()=>({ id: fromGlobalId('Item', obj => obj._id), // 或者,不是两者都有.. ID: { 类型:新的 GraphQLNonNull(GraphQLID), 解决: (obj) => obj._id }, 名称:{ 类型:GraphQLString }, 网址:{类型:GraphQLString}, 状态:{类型:GraphQLString}, 喜欢计数:{类型:GraphQLInt}, 创建时间:{ 类型:GraphQLString, 解决: ... } }), 接口:[节点接口] })

两者似乎都有效。如果你想分享你的代码,很高兴看到它。

【讨论】:

    猜你喜欢
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    相关资源
    最近更新 更多