realm / realm-graphql-service

GraphQL service for Realm Object Server
https://realm.io
Apache License 2.0
43 stars 10 forks source link

Add mass update support #92

Closed cedvdb closed 5 years ago

cedvdb commented 5 years ago

We would like to have a mutation where a query can be used to make many updates at once.

mutation updateManyProduct(productInput: ProductInput, query: String!).

nirinchev commented 5 years ago

This is not possible because Realm is not a SQL-based database. Updating many objects is supported by using the createProducts mutation and providing the updated values for all objects. You can use it like:

mutation {
  createProducts(input: [
    { productId: 123, valueToUpdate: "something" }
    { productId: 456, valueToUpdate: "something" }
  ]
  updatePolicy: MODIFIED
}
realm-probot[bot] commented 5 years ago

Hey - looks like you forgot to add a T:* label - could you please add one?

cedvdb commented 5 years ago

@nirinchev Yes that works for updating products where you already know the id. Props for that, it resolved some issues but not all of them.

This is not possible because Realm is not a SQL-based database.

The issue is that we have to query all the products on our website before doing an update. The update can be done internally in the graphql service without requiring the client to pass loads of ids under the network which is way slower. SQL or not, that can be done.

nirinchev commented 5 years ago

I agree, it can be done, but it's not easy to handle all the various corner cases precisely because Realm doesn't offer string based modification capabilities (like SQL databases do). It's quite straightforward for top-level properties (strings, integers, dates), but it gets a little tricky when you go into links, especially links without primary keys. I'm not against providing some sort of a mass update functionality, but it will require some design considerations and may take some time before we can prioritize it.

Originally the GraphQL service was designed to enable web apps to connect to the Realm Object Server, so it lacks some of the powerful editing capabilities that you seem to need. If you're accessing the data from a server, perhaps it's worth taking a look at the node.js or .NET SDKs? Those are more mature than the GraphQL API and are probably better suited for administrative tasks.

MichaelShakke commented 5 years ago

@nirinchev

This is not possible because Realm is not a SQL-based database. Updating many objects is supported by using the createProducts mutation and providing the updated values for all objects. You can use it like:

mutation {
  createProducts(input: [
    { productId: 123, valueToUpdate: "something" }
    { productId: 456, valueToUpdate: "something" }
  ]
  updatePolicy: MODIFIED
}

When trying to use the mutation createProducts as a many updater, it works for all the different types (string, int, objects) except for the boolean ones, if I try

mutation createProducts(input: [
     { id: 123, booleanValue: false },
     { id: 456, booleanValue: true }
    ],
    updatePolicy: MODIFIED
}

the value inside the object never gets updated, is there any way to fix this?

nirinchev commented 5 years ago

Can you please open a new issue with steps to reproduce and we'll look into that.