Skip to content

Commit b010e17

Browse files
committed
the introspection cache and buildkey solution
1 parent e0b55cc commit b010e17

43 files changed

Lines changed: 13056 additions & 7453 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ postgres/pgsql-test/output/
1313
.env.local
1414
graphql/server/logs/
1515
graphql/server/*.heapsnapshot
16+
graphql/server/perf/results/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# graphile-multi-tenancy-cache
2+
3+
Template-based multi-tenancy optimization for PostGraphile v5. Shares PostGraphile instances across tenants with identical schema structures using AST-based SQL rewriting.
4+
5+
## Features
6+
7+
- **Schema fingerprinting** — structural comparison (tables, columns, constraints) ignoring schema names
8+
- **Template sharing** — one PostGraphile instance per unique fingerprint, shared across N tenants
9+
- **AST-based SQL rewrite** — safe schema remapping via `pgsql-parser`/`pgsql-deparser`
10+
- **Three cache layers** — introspection cache, template registry, SQL rewrite cache (all LRU + TTL)
11+
- **No Crystal fork** — wrapper plugin intercepts at `withPgClient` level via Grafast middleware
12+
13+
## Architecture
14+
15+
```
16+
Request → authenticate → resolve tenant schemas
17+
→ introspection cache (fingerprint lookup)
18+
→ template registry (shared PostGraphile instance)
19+
→ PgMultiTenancyWrapperPlugin (client.query Proxy)
20+
→ AST rewrite cache (schema name remapping)
21+
→ PostgreSQL
22+
```
23+
24+
See [SPEC.md](./SPEC.md) for full architecture documentation.

graphile/graphile-multi-tenancy-cache/SPEC.md

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.tsx?$': [
7+
'ts-jest',
8+
{
9+
babelConfig: false,
10+
tsconfig: 'tsconfig.json',
11+
},
12+
],
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17+
modulePathIgnorePatterns: ['dist/*']
18+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "graphile-multi-tenancy-cache",
3+
"version": "0.1.0",
4+
"author": "Constructive <developers@constructive.io>",
5+
"description": "Template-based multi-tenancy cache for PostGraphile v5 — shares instances across tenants with identical schemas",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/constructive-io/constructive",
10+
"license": "MIT",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/constructive-io/constructive"
18+
},
19+
"scripts": {
20+
"clean": "makage clean",
21+
"prepack": "npm run build",
22+
"build": "makage build",
23+
"build:dev": "makage build --dev",
24+
"lint": "eslint . --fix",
25+
"test": "jest",
26+
"test:watch": "jest --watch"
27+
},
28+
"keywords": [
29+
"postgraphile",
30+
"graphile",
31+
"multi-tenancy",
32+
"cache",
33+
"template",
34+
"constructive",
35+
"v5"
36+
],
37+
"bugs": {
38+
"url": "https://github.com/constructive-io/constructive/issues"
39+
},
40+
"dependencies": {
41+
"@pgpmjs/logger": "workspace:^",
42+
"express": "^5.2.1",
43+
"grafserv": "1.0.0",
44+
"graphile-config": "1.0.0",
45+
"pg": "^8.11.3",
46+
"pg-env": "workspace:^",
47+
"pg-introspection": "1.0.0",
48+
"pgsql-deparser": "^17.18.2",
49+
"pgsql-parser": "^17.9.14",
50+
"postgraphile": "5.0.0"
51+
},
52+
"devDependencies": {
53+
"@types/express": "^5.0.6",
54+
"@types/pg": "^8.10.9",
55+
"makage": "^0.3.0",
56+
"ts-node": "^10.9.2"
57+
}
58+
}

0 commit comments

Comments
 (0)