https://kotlinlang.org logo
Title
d

Das135

09/30/2020, 9:57 AM
Hi. Does GraphQL kotlin preserve order of certain functions send in one graphql request? I have something like this:
mutation {
  deleteObj1(where){
    affectedRows
  }

  deleteObj2(where){
    affectedRows
  }

  deleteObj3(where){
    affectedRows
  }

  deleteObj4(where){
    affectedRows
  }
}
If order of executed functions will change, there can be thrown foreign key constraint condition -> I need to execute mutations like DELETE CASCADE...
l

Lenny

09/30/2020, 2:35 PM
The actual graphql executor comes from graphql-Java, and I’m sure it’s spec-compliant and runs mutations in sequence, top to bottom. But if you need transactionality, you should really wrap these up in a single mutation
d

Dariusz Kuc

09/30/2020, 5:10 PM
if you use
graphql-kotlin-spring-server
then by default yes they will execute sequentially, that being said - as was pointed above I’d highly recommend to refactor your schema to expose single mutation that handles all of that
*you could manually manage transaction around the whole request but I think it would be much simpler in single mutation
see: https://graphqlme.com/2018/05/13/transactions-mutations-and-graphql/ for a pretty good write up on this topic
c

Chris Voy

10/06/2020, 6:51 AM
Treat each mutation independently. Just like with resolvers, how you execute (serially, sequentially) is implementation detail.