Mithir
Mithir

Reputation: 2421

neo4j graphql with multiple users

We started using @neo4j/graphql to have a graphql over our neo4j graph db.

The only problem is that according to the getting started example it is only possible to init the Apollo Server with a single user (driver).

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

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

This causes an issue with our RBAC approach as we try to create a user per tenant and deny cross-reads.

Is there a way to use multiple drivers (per user) so that we can map each request to a different user?

Upvotes: 2

Views: 223

Answers (1)

Mithir
Mithir

Reputation: 2421

I think I found an answer to my question...

Instead of supplying a driver (user) for the server initialization, we can use a driver in context approach

Which will look something like this

neoSchema.getSchema().then((schema) => {
    const server = new ApolloServer({
        schema,
        context: ({ req }) => ({ req, some-function-to-extract-driver-from-req }),
    });
});

Upvotes: 1

Related Questions