Search code examples
facebookreactjsrelayjsgraphql-js

GraphQL Relay relationships and mutation


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


Solution

  • 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.