cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Using 2 databases for neo4j/graphql

Hello, I have to neo4j databases and I want to serve data from each using a single nodejs server. How do I achieve this.

1 REPLY 1

William_Lyon
Graph Fellow

You can specify the Neo4j database name to use for resolving GraphQL queries in the GraphQL context object. For example:

 

const { Neo4jGraphQL } = require("@neo4j/graphql");
const neo4j = require("neo4j-driver");

const typeDefs = `
    type User {
        name: String
    }
`;

const driver = neo4j.driver(
    "bolt://localhost:7687",
    neo4j.auth.basic("neo4j", "password")
);

const neoSchema = new Neo4jGraphQL({ typeDefs, driver });

neoSchema.getSchema().then((schema) => {
    const server = new ApolloServer({
        schema,
        context: { driverConfig: { database: "my-database" } },
    });
});

 

context can be a function that determines which Neo4j database to use at query time. See the docs here: https://neo4j.com/docs/graphql-manual/current/driver-configuration/