Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic arangodb database change #127

Open
mihazs opened this issue Dec 9, 2019 · 0 comments
Open

Dynamic arangodb database change #127

mihazs opened this issue Dec 9, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@mihazs
Copy link

mihazs commented Dec 9, 2019

Hello.
It's possible to change the database name based on context?
I want to change the database name based in the request headers, it will be nice to do something like this:

import { ArangoDBAdapter } from "cruddl";
import { ApolloServer } from "apollo-server";
const schema = project.createSchema(db);
db.updateSchema(project.getModel()); // create missing collections
const db = new ArangoDBAdapter({
  databaseName: "databaseName",
  url: "http://root:@localhost:8529",
  user: "root",
  password: ""
});
const server = new ApolloServer({
  schema,
  context: ({ req }) => { 
    const {tenantId} = jwt.verify(req.headers.authorization);
    db.setDatabseName(tenantId);
    return req;
  } 
});
server.listen(4000, () =>
  console.log("Server is running on http://localhost:4000/")
);

It very useful for build multi tenant system with database isolation.

@Yogu Yogu added the enhancement New feature or request label Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants