reactjs – 尝试在GraphQLSegment中添加ID

我的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对象吗?如何使警告静音或至少进一步调试?

可以告诉你看看代码,但你可能在你的类型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 
}

)

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

let itemType = new GraphQLObjectType({
    名称:’项目’,
    fields:()=> ({
      id:fromGlobalId(‘Item’,obj => obj._id),
      //或者,不是两个..
      ID: {
        type:new GraphQLNonNull(GraphQLID),
        解决:(obj)=> obj._id
      },
      name:{type:GraphQLString},
      url:{type:GraphQLString},
      state:{type:GraphQLString},
      likesCount:{type:GraphQLInt},
      createdAt:{
        type:GraphQLString,
        解决:……
      }
    }),
    接口:[nodeInterface]
  })

要么似乎工作.如果你想分享你的代码,很高兴看到它.

相关文章
相关标签/搜索