Nobody Pays (for) Magazines
Miss any of our Open RFC calls?Watch the recordings here! »

@prisma-multi-tenant/redwood

2.3.1 • Public • Published

Redwood plugin for Prisma-multi-tenant 🧭

Version Documentation Maintenance License: MIT Twitter: Errorname_

🧭 Add multi-tenancy to your Redwood application

Installation

yarn global add prisma-multi-tenant # CLI for tenant management 
yarn add @prisma-multi-tenant/redwood # Redwood plugin 
 
cp api/
prisma-multi-tenant init # Init multi-tenancy in your Redwood project 

Usage

⚠️ First, make sure you followed the Prisma-multi-tenant Getting Started Guide. ⚠️

First, replace the code in api/src/lib/db.js with the following:

import { MultiTenant, fromContext } from '@prisma-multi-tenant/redwood'
 
export const multiTenant = new MultiTenant()
export const db = fromContext()

Then, update the code in api/src/functions/graphql.js:

import { multiTenant } from 'src/lib/db'
 
export const handler = createGraphQLHandler({
  schema: makeMergedSchema({
    schemas,
    services: makeServices({ services }),
  }),
  context: async ({ event }) => ({
    // The name can come from anywhere (headers, token, ...)
    db: await multiTenant
      .get('dev') // or 'my_tenant_A' or anything
      .catch(console.error),
  }),
})

Example

Check out an example application using Redwood and the multi-tenant plugin here.

Documentation

Read more on how prisma-multi-tenant can help you achieve multi-tenancy for your apps:

Author

👤 Thibaud Courtoison

🤝 Contributors

Contributions, issues, and feature requests are welcome! 🙌

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 Thibaud Courtoison.

This project is MIT licensed.

Install

npm i @prisma-multi-tenant/redwood

DownloadsWeekly Downloads

3

Version

2.3.1

License

MIT

Unpacked Size

6.04 kB

Total Files

4

Last publish

Collaborators

  • avatar