How to use cypherMutation function from neo4j-graphql-js

I have a mutation in my graphQL schema that I want to resolve manually.

I came across the cypherMutation function in the docs but I find the description a little lacking without an example.

Can someone provide a simple example using the cypherMutation within a resolver to connect to a neo4j database and resove a graphQL request?

Hi @Banhawy - the idea of the cypherMutation (and cypherQuery) function is to just generate the Cypher query (and Cypher parameters) for a specific GraphQL request without handling the call to the database. A use case for when to use cypherMutation instead of the auto-generated mutations would be if you want to have some additional authorization logic before sending the query to the database.

You can see some examples of using cypherMutation in the tests for neo4j-graphql-js: https://github.com/neo4j-graphql/neo4j-graphql-js/blob/master/test/helpers/cypherTestHelpers.js#L56-L82

1 Like

Oh I initially thought I had to define the Cypher query both in the GraphQL schema and in the resolver, this makes much more sense.

Thanks @William_Lyon!

This question approaches one that I have which is how to query the database from the api side of the application. For example, if I wanted to query graphql in place of Users.findOne() within a passport strategy like in the authentication/authorization blog code examples