0
votes

I'm very confused regarding the the relations in GraphQL-Relay. When its about one-to-many it seems very straightforward. I created some connectionDefinitions and it worked perfectly. 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?

If I look at the config for 'RANGE_ADD' it shows parentName and parentId but in my case I have more than one parent. Should I have two objects configuration (one for each parent) in my getConfigs array?

Can I create and update this object without a connection?

Thanks

1
A connection is an abstraction for a client side list, for a single model, there is no need for a connection.brysgo
"but in my case I have more than one parent." -- How does your example have more than one parent?Ahmad Ferdous
@AhmadFerdous a User and an Item, actually they are not really parents but more a reverse relation. At this time, I believed I had to use RANGE_ADDsamidarko
Do you mean that there will be only one instance of (item, user, liked) data?Your answer is as confusing as your question.Ahmad Ferdous
sorry about that @AhmadFerdous, only one instance of (item, user), there is a unique-together constraint between them. Hope it clarifies.samidarko

1 Answers

0
votes

Should I create a connection with User and Item in my GraphQL Schema?

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?

RANGE_ADD is the appropriate configuration to create and delete. Only one configuration is enough.