简体   繁体   English

GraphQL中继关系和变异

[英]GraphQL Relay relationships and mutation

I'm very confused regarding the the relations in GraphQL-Relay. 我对GraphQL-Relay中的关系感到非常困惑。 When its about one-to-many it seems very straightforward. 当一对多时,它看起来非常简单。 I created some connectionDefinitions and it worked perfectly. 我创建了一些connectionDefinitions ,并且效果很好。 But I have the following case where I would like to create / update the model below. 但是在以下情况下,我想创建/更新以下模型。

new Schema({
    item: {type: String, ref: ‘Item’, required: true},
    user: {type: String, ref: ‘User’, required: true},
    liked: {type: Boolean, required: true, default: false}
})

Should I create a connection with User and Item in my GraphQL Schema? 我应该在GraphQL模式中与User和Item建立连接吗?

If I look at the config for 'RANGE_ADD' it shows parentName and parentId but in my case I have more than one parent. 如果我查看“ RANGE_ADD”的配置 ,它会显示parentName和parentId,但就我而言,我有多个父级。 Should I have two objects configuration (one for each parent) in my getConfigs array? 我的getConfigs数组中是否应该有两个对象配置(每个父对象一个)?

Can I create and update this object without a connection? 我可以在没有连接的情况下创建和更新该对象吗?

Thanks 谢谢

Should I create a connection with User and Item in my GraphQL Schema? 我应该在GraphQL模式中与User和Item建立连接吗?

Not necessary as relations are more for one-to-many and my interaction object has to one-to-one relations. 关系不是必须的,因为一对多关系更重要,并且我的交互对象必须一对一关系。 Connections are useful for pagination 连接对于分页很有用

Which getConfigs should I use? 我应该使用哪个getConfigs?

RANGE_ADD is the appropriate configuration to create and delete. RANGE_ADD是创建和删除的适当配置。 Only one configuration is enough. 仅一种配置就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM