How to use cypherMutation function from neo4j-graphql-js

operations
knowledge-base

(Banhawy) #1

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?


(William Lyon) #2

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


(Banhawy) #3

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!