Filtering Connections in PostGraphile by Tenants
Disclaimer & Compatibility
This plugin still in very alpha version. It targets the alpha release of PostGraphile v4.
Bug reports and pull requests are very much welcome.
Multi Tenant Database
The main drawback of Multi Tenant with shared-tables is the need to append the tenant filter condition onto every single query in the application layer.
One possible way to isolate tenants is to add
tenant_id to every table, and scope every request with that field.
This plugin will filter tables (Connections) by looking for table with column name specified by
tenantColumnName at graphileBuildOptions.
Currently, the collections will be filtered by using
tenant_id (stored in jwt).
tenant_id in your schema, i.e :
create type store_example.jwt_token as ( tenant_id text role text, person_id integer );
- optional tables autofilter by
- add test
postgraphile --append-plugins `pwd`/path/to/this/plugin/index.js
const express = ;const postgraphile = ;const PostGraphileConnectionMultiTenantPlugin = ;const app = ;app;app;
When using PostGraphile as a library, the following plugin options can be passed via
graphqlBuildOptions in PostGraphile 4.0.0-alpha2.20 and earlier):
Target column :