cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch data from multiple neo4j servers in GRANDStack?

kamesh_s
Node

My application has 3 data sources: two neo4j graph dbs at different servers and a Postgres db.

The neo4j-graphql-js allows to create a single neo4j.driver that holds the neo4j server and authentication details. One can handle multiple dbs (multi-tenancy) from the same neo4j server by specifying the appropriate db name in context.neo4jDatabase

How can I connect to two different neo4j servers, which would require two neo4j.driver? What are the best practices for this scenario? One option is to write custom resolvers for one or both the neo4j servers.

Hope this gets covered in the livebook Fullstack GraphQL Applications with GRANDstack.

2 REPLIES 2

William_Lyon
Graph Fellow

Since the driver instance is passed in the context function at query time you could have some logic in the context function that determines which driver instance to return. This won't necessarily work if you have a single GraphQL request that needs to resolve data from two separate Neo4j instances, so for that case the better option is as you suggest to implement resolvers for one of the Neo4j instances.

This also sounds like a potential use case for GraphQL schema stitching or schema delegation so those might be options to explore as well. There's an example of using schema stitching with neo4j-graphql-js here.

This topic is not covered in the book you mention as resolving GraphQL operations against multiple Neo4j DBMS instances is not a common use case that comes up.

Thanks William.

GraphQL schema stitching is more applicable for my case.