graphile-i18n 2.19.0 → 2.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/plugin.js +7 -6
- package/package.json +5 -5
- package/plugin.js +6 -5
package/esm/plugin.js
CHANGED
|
@@ -20,7 +20,7 @@ import 'graphile-build';
|
|
|
20
20
|
import 'graphile-build-pg';
|
|
21
21
|
import { TYPES } from '@dataplan/pg';
|
|
22
22
|
import { context as grafastContext, lambda, object } from 'grafast';
|
|
23
|
-
import {
|
|
23
|
+
import { withRequestPgClient } from 'graphile-plugin-utils';
|
|
24
24
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
25
25
|
function hasI18nTag(codec) {
|
|
26
26
|
const tags = codec.extensions?.tags;
|
|
@@ -239,16 +239,18 @@ export function createI18nPlugin(options = {}) {
|
|
|
239
239
|
$baseCols[column] = $parent.get(column);
|
|
240
240
|
}
|
|
241
241
|
const $withPgClient = grafastContext().get('withPgClient');
|
|
242
|
+
const $pgSettings = grafastContext().get('pgSettings');
|
|
242
243
|
const $langCodes = grafastContext().get('langCodes');
|
|
243
244
|
// Combine all inputs into a single step
|
|
244
245
|
const $input = object({
|
|
245
246
|
id: $id,
|
|
246
247
|
withPgClient: $withPgClient,
|
|
248
|
+
pgSettings: $pgSettings,
|
|
247
249
|
langCodes: $langCodes,
|
|
248
250
|
...$baseCols,
|
|
249
251
|
});
|
|
250
252
|
return lambda($input, async (input) => {
|
|
251
|
-
const { id, withPgClient, langCodes: ctxLangCodes, ...baseCols } = input;
|
|
253
|
+
const { id, withPgClient, pgSettings, langCodes: ctxLangCodes, ...baseCols } = input;
|
|
252
254
|
const langs = ctxLangCodes ?? defaultLanguages;
|
|
253
255
|
if (!withPgClient || !id) {
|
|
254
256
|
const result = { [langCodeGqlField]: null };
|
|
@@ -257,10 +259,9 @@ export function createI18nPlugin(options = {}) {
|
|
|
257
259
|
}
|
|
258
260
|
return result;
|
|
259
261
|
}
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
const row = await withSystemLaneClient(withPgClient, async (client) => {
|
|
262
|
+
// Translations are the tenant's own rows: read them as the
|
|
263
|
+
// request's role, under its jwt claims and RLS.
|
|
264
|
+
const row = await withRequestPgClient(withPgClient, pgSettings, async (client) => {
|
|
264
265
|
const { rows } = await client.query({ text: sqlQuery, values: [id, langs] });
|
|
265
266
|
return rows[0] ?? null;
|
|
266
267
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-i18n",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.2",
|
|
4
4
|
"description": "PostGraphile v5 i18n plugin — language-aware fields from @i18n translation tables with Accept-Language negotiation and fallback chains",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/constructive",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"accept-language-parser": "^1.5.0",
|
|
33
|
-
"graphile-plugin-utils": "^1.14.
|
|
33
|
+
"graphile-plugin-utils": "^1.14.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@dataplan/pg": "^1.1.1",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"@types/accept-language-parser": "^1.5.4",
|
|
47
47
|
"@types/node": "^22.19.11",
|
|
48
48
|
"@types/pg": "^8.20.4",
|
|
49
|
-
"graphile-test": "^5.18.
|
|
49
|
+
"graphile-test": "^5.18.2",
|
|
50
50
|
"makage": "^0.8.0",
|
|
51
51
|
"pg": "^8.21.0",
|
|
52
|
-
"pgsql-test": "^5.18.
|
|
52
|
+
"pgsql-test": "^5.18.1"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"postgraphile",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"accept-language",
|
|
65
65
|
"locale"
|
|
66
66
|
],
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0b4ffa11a6d7958ba1068ce8e19616d4b018c0d6"
|
|
68
68
|
}
|
package/plugin.js
CHANGED
|
@@ -243,16 +243,18 @@ function createI18nPlugin(options = {}) {
|
|
|
243
243
|
$baseCols[column] = $parent.get(column);
|
|
244
244
|
}
|
|
245
245
|
const $withPgClient = (0, grafast_1.context)().get('withPgClient');
|
|
246
|
+
const $pgSettings = (0, grafast_1.context)().get('pgSettings');
|
|
246
247
|
const $langCodes = (0, grafast_1.context)().get('langCodes');
|
|
247
248
|
// Combine all inputs into a single step
|
|
248
249
|
const $input = (0, grafast_1.object)({
|
|
249
250
|
id: $id,
|
|
250
251
|
withPgClient: $withPgClient,
|
|
252
|
+
pgSettings: $pgSettings,
|
|
251
253
|
langCodes: $langCodes,
|
|
252
254
|
...$baseCols,
|
|
253
255
|
});
|
|
254
256
|
return (0, grafast_1.lambda)($input, async (input) => {
|
|
255
|
-
const { id, withPgClient, langCodes: ctxLangCodes, ...baseCols } = input;
|
|
257
|
+
const { id, withPgClient, pgSettings, langCodes: ctxLangCodes, ...baseCols } = input;
|
|
256
258
|
const langs = ctxLangCodes ?? defaultLanguages;
|
|
257
259
|
if (!withPgClient || !id) {
|
|
258
260
|
const result = { [langCodeGqlField]: null };
|
|
@@ -261,10 +263,9 @@ function createI18nPlugin(options = {}) {
|
|
|
261
263
|
}
|
|
262
264
|
return result;
|
|
263
265
|
}
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
const row = await (0, graphile_plugin_utils_1.withSystemLaneClient)(withPgClient, async (client) => {
|
|
266
|
+
// Translations are the tenant's own rows: read them as the
|
|
267
|
+
// request's role, under its jwt claims and RLS.
|
|
268
|
+
const row = await (0, graphile_plugin_utils_1.withRequestPgClient)(withPgClient, pgSettings, async (client) => {
|
|
268
269
|
const { rows } = await client.query({ text: sqlQuery, values: [id, langs] });
|
|
269
270
|
return rows[0] ?? null;
|
|
270
271
|
});
|