title: Graphene Graphql - how to chain mutations
body: <p>I happened to send 2 separated requests to a Graphql API (Python3 + Graphene) in order to:</p>
  
  <ol>
  <li>Create an object</li>
  <li>Update another object so that it relates to the created one.</li>
  </ol>
  
  <p>I sensed this might not be in the "spirit" of Graphql, so I searched and read about <a href="https://www.freecodecamp.org/news/organizing-graphql-mutations-653306699f3d/" rel="noreferrer">nested migrations</a>. Unforutnately, I also found that it was <a href="https://www.freecodecamp.org/news/beware-of-graphql-nested-mutations-9cdb84e062b5/" rel="noreferrer">bad practice</a> because nested migrations are not sequential and it might lead clients in hard to debug problems due to race conditions.</p>
  
  <p>I'm trying to use sequential root mutations in order to implement the use cases where nested migrations were considered. Allow me to present you a use case and a simple solution (but probably not good practice) I imagined. Sorry for the long post coming.</p>
  
  <p>Let's image I have User and Group entities, and I want, from the client form to update a group, to be able to not only add a user, but also create a user to be added in a group if the user does not exist. The users have ids named uid (user id) and groups gid (groupd id), just to highlight the difference. So using root mutations, I imagine doing a query like:</p>
  
  <pre><code>mutation {
      createUser(uid: "b53a20f1b81b439", username: "new user", password: "secret"){
          uid
          username
      }
  
      updateGroup(gid: "group id", userIds: ["b53a20f1b81b439", ...]){
          gid
          name
      }
  }
  </code></pre>
  
  <p>You noticed that I provide the user id in the input of the <code>createUser</code> mutation. My problem is that to make the <code>updateGroup</code> mutation, I need the ID of the newly created user. I don't know  a way to get that in graphene inside the mutate methods resolving <code>updateGroup</code>, so I imagined querying a UUID from the API while loading the client form data. So before sending the mutation above, at the initial loading of my client, I would do something like:</p>
  
  <pre><code>query {
      uuid
  
      group (gid: "group id") {
          gid
          name
      }
  }
  </code></pre>
  
  <p>Then I would use the uuid from the response of this query in the mutation request (the value would be <code>b53a20f1b81b439</code>, as in the the first scriptlet above).</p>
  
  <p>What do you think about this process ? Is there a better way to do that ? Is Python <code>uuid.uuid4</code> safe to implement this ?</p>
  
  <p>Thanks in advance.</p>
  
  <p>----- EDIT</p>
  
  <p>Based on a discussion in the comments, I should mention that the use case above is for illustration only. Indeed, a User entity might have an intrinsic unique key (email, username), as well as other entities might (ISBN for Book...). I'm looking for a general case solution, including for entities that might not exhibit such natural unique keys.</p>