Manipulate data inside graphql and add more business logic in resolvers

Hi all,

I'm facing an issue with neo4j-graphql-js npm module. I want to manipulate data inside GraphQL resolvers (like an OGM with models: findAll, findById, update, etc.) to add more business logic. But neo4j-graphql-js doesn't provide a way to do it, just maps GraphQL functions to one cypher query.

My typical use case is the following:
I have Article and Tag nodes. An Article can be tagged by multiple Tags. So, when I create an Article, I want to create the Article but Tags and relations too. I can do it with a single cypher but I think isn't the proper way when the app will growth.

To solve this issue, I found two ways:

  • The one is to use an OGM (neo4j-node-ogm) instead of (or in addition to) neo4j-graphql. The cons of this method is that we have to redefine models in addition to existing graphql schema and be careful about changes between both.
  • The other solution would be to create a new graphQL API over the existing graphQL and use blueprint functions autogenerated by neo4j-graphql-js on the second one to manipulate data at the top level.

What is the best way ? Or is there another way to solve it ?

Thanks !

Are you sure the @cypher directives and custom resolvers outlined here don't provide the functionality you're after?

I think not, because @cypher directives add more logic to types and functions, but in custom resolvers I can't access to these models and their functions. So, if I want to check if a resource A exists in the database before create a resource B, I haven't any tool to do it currently. The idea would be to expose auto-generated functions into the graphql context to use them inside resolvers (like an ORM/OGM).

Finally, my solution was to package neo4j-graphql as a microservice, requested by my business logic layer