Doing 2 mutations at once

We're using neo4j-graphql-js. It's absolutly incredible tool. Managing a database and API thru a simple Schema is amazing approach. Thank you so much for that. We're huge fan.

I'm trying to figurate how to do a simple mutation which involve 2 mutations. Let me explain:
When I do CreateMyType() mutation, it's always followed by a mutation addMyType1ParentType() to link the created node to a related node. This example is show the most simple case but often, there's more than 2 mutations (as there's many link and node creation related to the creation of one node) which needs to be done in one requests from the front end.

I'm wondering how you plan to make such mutations easier. I've to plan with my dev team the best approach to do that.

Would it be to write custom resolvers which will be in charge to receive one "call" from the frontend, and then, do the few mutations with existing mutations created by neo4j-graphql-js, and respond to the frontend whatever is needed ?
Or what would you suggest?

Also, in the background of this question, there's the notion of transaction. If one mutation fail, all should fail.

This demand is quite urgent for us.

Thank you so much

Jonas

Hi @jonasdumas -

Currently, the options are:

  1. Use a @cypher schema directive on a mutation field with the logic for creating the node and relationship in a single Cypher query. Since the logic is defined in a single Cypher query it will execute in a single transaction.
  2. Implement a custom resolver that implements this logic using the Neo4j JavaScript driver injected into the context object of the resolver.

Eventually, we plan to add nested mutations that would allow for much more complex operations using the auto-generated mutations, similar to this example. However this is not yet implemented.

1 Like

Hi @lyonwj

Thank you so much for your quick answer.

Very clear. I see better the approach to use to be efficient.

  1. Using MERGE mutation whenever it's possible as a single @cypher mutation with many database updates.
  2. Writing custom resolvers on more complexe mutations which involve conditionals logics and specific responses to the front.

Looking forward to see upcoming features!

Any rough idea when theses two upcoming features will be available?

  1. Nested mutations
  2. Subsciptions
2 Likes

Hi @lyonwj im new to neo4j in general neo4j-graphql.js is looking very interesting for integrating with graphql.

Is there a feature roadmap somewhere that we can refer to?