@graphql-mesh/transport-sql 0.0.0-stage → 0.1.0
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/CHANGELOG.md +9 -0
- package/dist/cjs/adapter.js +60 -0
- package/dist/cjs/batch.js +113 -0
- package/dist/cjs/client.js +205 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/dialect.js +60 -0
- package/dist/cjs/dialect.js.map +7 -0
- package/dist/cjs/entity.js +186 -0
- package/dist/cjs/execution.js +307 -0
- package/dist/cjs/execution.js.map +7 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/mapping.js +260 -0
- package/dist/cjs/mapping.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pg-executor.js +53 -0
- package/dist/cjs/pg-plans.js +103 -0
- package/dist/cjs/pg-registry.js +239 -0
- package/dist/cjs/plan.js +359 -0
- package/dist/cjs/sql-builder.js +653 -0
- package/dist/cjs/sql-builder.js.map +7 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/uri.js +267 -0
- package/dist/esm/adapter.js +54 -0
- package/dist/esm/batch.js +107 -0
- package/dist/esm/client.js +197 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/dialect.js +54 -0
- package/dist/esm/dialect.js.map +7 -0
- package/dist/esm/entity.js +180 -0
- package/dist/esm/execution.js +303 -0
- package/dist/esm/execution.js.map +7 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/mapping.js +255 -0
- package/dist/esm/mapping.js.map +7 -0
- package/dist/esm/pg-executor.js +49 -0
- package/dist/esm/pg-plans.js +100 -0
- package/dist/esm/pg-registry.js +236 -0
- package/dist/esm/plan.js +351 -0
- package/dist/esm/sql-builder.js +636 -0
- package/dist/esm/sql-builder.js.map +7 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/uri.js +261 -0
- package/dist/package.json +57 -0
- package/dist/typings/adapter.d.cts +9 -0
- package/dist/typings/adapter.d.ts +9 -0
- package/dist/typings/batch.d.cts +21 -0
- package/dist/typings/batch.d.ts +21 -0
- package/dist/typings/client.d.cts +36 -0
- package/dist/typings/client.d.ts +36 -0
- package/dist/typings/dialect.d.cts +9 -0
- package/dist/typings/dialect.d.ts +9 -0
- package/dist/typings/entity.d.cts +24 -0
- package/dist/typings/entity.d.ts +24 -0
- package/dist/typings/execution.d.cts +9 -0
- package/dist/typings/execution.d.ts +9 -0
- package/dist/typings/index.d.cts +15 -0
- package/dist/typings/index.d.ts +15 -0
- package/dist/typings/mapping.d.cts +13 -0
- package/dist/typings/mapping.d.ts +13 -0
- package/dist/typings/pg-executor.d.cts +19 -0
- package/dist/typings/pg-executor.d.ts +19 -0
- package/dist/typings/pg-plans.d.cts +12 -0
- package/dist/typings/pg-plans.d.ts +12 -0
- package/dist/typings/pg-registry.d.cts +16 -0
- package/dist/typings/pg-registry.d.ts +16 -0
- package/dist/typings/plan.d.cts +47 -0
- package/dist/typings/plan.d.ts +47 -0
- package/dist/typings/sql-builder.d.cts +75 -0
- package/dist/typings/sql-builder.d.ts +75 -0
- package/dist/typings/types.d.cts +50 -0
- package/dist/typings/types.d.ts +50 -0
- package/dist/typings/uri.d.cts +42 -0
- package/dist/typings/uri.d.ts +42 -0
- package/package.json +67 -4
- package/src/adapter.ts +56 -0
- package/src/batch.ts +150 -0
- package/src/client.ts +233 -0
- package/src/entity.ts +235 -0
- package/src/execution.ts +411 -0
- package/src/index.ts +25 -0
- package/src/mapping.ts +291 -0
- package/src/pg-executor.ts +68 -0
- package/src/pg-plans.ts +118 -0
- package/src/pg-registry.ts +290 -0
- package/src/plan.ts +466 -0
- package/src/sql-builder.ts +809 -0
- package/src/types.ts +63 -0
- package/src/uri.ts +301 -0
- package/test/client-bun.test.ts +8 -0
- package/test/client.bun.test.ts +46 -0
- package/test/execution.test.ts +277 -0
- package/test/mapping.test.ts +79 -0
- package/test/pg-registry.test.ts +103 -0
- package/test/sql-builder.test.ts +131 -0
- package/test/uri.test.ts +123 -0
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @graphql-mesh/transport-sql
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Initial release: execute `@sql` with transport `kind: "sql"` (sqlite / mysql / postgres).
|
|
8
|
+
Type-level `@sql` wires Federation `resolveReference` + `Query._entities`; ROW/ROWS equality
|
|
9
|
+
lookups are DataLoader-batched.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferAdapterFromLocation = inferAdapterFromLocation;
|
|
4
|
+
exports.quoteIdent = quoteIdent;
|
|
5
|
+
exports.placeholder = placeholder;
|
|
6
|
+
exports.resolveSqlitePath = resolveSqlitePath;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const uri_js_1 = require("./uri.js");
|
|
9
|
+
/**
|
|
10
|
+
* Infer adapter from a transport `location` / connection URI.
|
|
11
|
+
* Prefer {@link inferAdapterFromConnectionString} for full Bun-compatible rules.
|
|
12
|
+
*/
|
|
13
|
+
function inferAdapterFromLocation(location) {
|
|
14
|
+
if (!location)
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
return (0, uri_js_1.inferAdapterFromConnectionString)(location);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function quoteIdent(adapter, name) {
|
|
24
|
+
switch (adapter) {
|
|
25
|
+
case 'mysql':
|
|
26
|
+
return `\`${name.replace(/`/g, '``')}\``;
|
|
27
|
+
case 'postgres':
|
|
28
|
+
case 'sqlite':
|
|
29
|
+
default:
|
|
30
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function placeholder(adapter, index) {
|
|
34
|
+
// index is 1-based for postgres
|
|
35
|
+
if (adapter === 'postgres') {
|
|
36
|
+
return `$${index}`;
|
|
37
|
+
}
|
|
38
|
+
return '?';
|
|
39
|
+
}
|
|
40
|
+
function resolveSqlitePath(location, cwd) {
|
|
41
|
+
let path = location;
|
|
42
|
+
if (path.startsWith('file:')) {
|
|
43
|
+
path = path.slice('file:'.length);
|
|
44
|
+
}
|
|
45
|
+
else if (path.toLowerCase().startsWith('sqlite:')) {
|
|
46
|
+
path = path.slice(path.indexOf(':') + 1);
|
|
47
|
+
}
|
|
48
|
+
if (path.startsWith('//')) {
|
|
49
|
+
// file://absolute or file:///absolute
|
|
50
|
+
path = path.replace(/^\/\/+/, '/');
|
|
51
|
+
}
|
|
52
|
+
const qIdx = path.indexOf('?');
|
|
53
|
+
if (qIdx !== -1) {
|
|
54
|
+
path = path.slice(0, qIdx);
|
|
55
|
+
}
|
|
56
|
+
if (!(0, node_path_1.isAbsolute)(path) && cwd && path !== ':memory:') {
|
|
57
|
+
return (0, node_path_1.join)(cwd, path);
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.batchableEqualityColumn = batchableEqualityColumn;
|
|
4
|
+
exports.resolveEqualityKey = resolveEqualityKey;
|
|
5
|
+
exports.loadBatchedByColumn = loadBatchedByColumn;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const dataloader_1 = tslib_1.__importDefault(require("dataloader"));
|
|
8
|
+
const mapping_js_1 = require("./mapping.js");
|
|
9
|
+
const sql_builder_js_1 = require("./sql-builder.js");
|
|
10
|
+
const LOADERS = Symbol.for('mesh.sql.loaders');
|
|
11
|
+
function getLoaderMap(context) {
|
|
12
|
+
if (!context || typeof context !== 'object') {
|
|
13
|
+
throw new Error('SQL DataLoader batching requires a mutable GraphQL context object');
|
|
14
|
+
}
|
|
15
|
+
if (!context[LOADERS]) {
|
|
16
|
+
context[LOADERS] = new Map();
|
|
17
|
+
}
|
|
18
|
+
return context[LOADERS];
|
|
19
|
+
}
|
|
20
|
+
function stableArgsKey(args) {
|
|
21
|
+
if (!args)
|
|
22
|
+
return '';
|
|
23
|
+
const { filter, orderBy, limit, offset, first, after } = args;
|
|
24
|
+
return JSON.stringify({ filter, orderBy, limit, offset, first, after });
|
|
25
|
+
}
|
|
26
|
+
const PLANNER_KEYS = new Set([
|
|
27
|
+
'filter',
|
|
28
|
+
'orderBy',
|
|
29
|
+
'first',
|
|
30
|
+
'after',
|
|
31
|
+
'last',
|
|
32
|
+
'before',
|
|
33
|
+
'limit',
|
|
34
|
+
'offset',
|
|
35
|
+
'set',
|
|
36
|
+
'where',
|
|
37
|
+
]);
|
|
38
|
+
/**
|
|
39
|
+
* Detect a single equality column binder suitable for `WHERE col IN (...)` batching.
|
|
40
|
+
*/
|
|
41
|
+
function batchableEqualityColumn(whereMapping) {
|
|
42
|
+
const cols = [];
|
|
43
|
+
for (const entry of whereMapping.entries) {
|
|
44
|
+
if (PLANNER_KEYS.has(entry.key) || entry.children)
|
|
45
|
+
continue;
|
|
46
|
+
cols.push(entry.key);
|
|
47
|
+
}
|
|
48
|
+
return cols.length === 1 ? cols[0] : undefined;
|
|
49
|
+
}
|
|
50
|
+
function resolveEqualityKey(whereMapping, column, graphqlArgs, parent) {
|
|
51
|
+
const entry = whereMapping.entries.find(e => e.key === column);
|
|
52
|
+
if (!entry)
|
|
53
|
+
return undefined;
|
|
54
|
+
return (0, mapping_js_1.resolveMappingValue)(entry.value, { args: graphqlArgs, parent });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Per-request DataLoader that batches ROW/ROWS lookups sharing the same table/column/args.
|
|
58
|
+
*/
|
|
59
|
+
function loadBatchedByColumn(context, opts, key) {
|
|
60
|
+
const loaderKey = [
|
|
61
|
+
opts.kind,
|
|
62
|
+
opts.table,
|
|
63
|
+
opts.column,
|
|
64
|
+
stableArgsKey(opts.graphqlArgs),
|
|
65
|
+
JSON.stringify(opts.selection.entries.map(e => [e.key, e.value])),
|
|
66
|
+
].join('\0');
|
|
67
|
+
const map = getLoaderMap(context);
|
|
68
|
+
let loader = map.get(loaderKey);
|
|
69
|
+
if (!loader) {
|
|
70
|
+
loader = new dataloader_1.default(async (keys) => {
|
|
71
|
+
const unique = [...new Set(keys.filter(k => k !== undefined && k !== null))];
|
|
72
|
+
if (!unique.length) {
|
|
73
|
+
return keys.map(() => (opts.kind === 'ROWS' ? [] : null));
|
|
74
|
+
}
|
|
75
|
+
const query = (0, sql_builder_js_1.buildSelectByColumnIn)(opts.client.adapter, {
|
|
76
|
+
table: opts.table,
|
|
77
|
+
kind: 'ROWS',
|
|
78
|
+
selection: opts.selection,
|
|
79
|
+
whereMapping: opts.whereMapping,
|
|
80
|
+
planners: opts.planners,
|
|
81
|
+
graphqlArgs: opts.graphqlArgs || {},
|
|
82
|
+
column: opts.column,
|
|
83
|
+
values: unique,
|
|
84
|
+
});
|
|
85
|
+
const result = await opts.client.query(query.sql, query.params);
|
|
86
|
+
const rows = result.rows;
|
|
87
|
+
const byKey = new Map();
|
|
88
|
+
for (const row of rows) {
|
|
89
|
+
const raw = row[opts.column] ?? row[opts.column.toLowerCase()] ?? row[opts.column.toUpperCase()];
|
|
90
|
+
const k = String(raw);
|
|
91
|
+
let list = byKey.get(k);
|
|
92
|
+
if (!list) {
|
|
93
|
+
list = [];
|
|
94
|
+
byKey.set(k, list);
|
|
95
|
+
}
|
|
96
|
+
list.push(row);
|
|
97
|
+
}
|
|
98
|
+
return keys.map(k => {
|
|
99
|
+
if (k === undefined || k === null) {
|
|
100
|
+
return opts.kind === 'ROWS' ? [] : null;
|
|
101
|
+
}
|
|
102
|
+
const matched = byKey.get(String(k)) || [];
|
|
103
|
+
if (opts.kind === 'ROW') {
|
|
104
|
+
const row = matched[0];
|
|
105
|
+
return row ? (0, sql_builder_js_1.mapRowToGraphql)(row, opts.selection) : null;
|
|
106
|
+
}
|
|
107
|
+
return matched.map(r => (0, sql_builder_js_1.mapRowToGraphql)(r, opts.selection));
|
|
108
|
+
});
|
|
109
|
+
}, { cache: true });
|
|
110
|
+
map.set(loaderKey, loader);
|
|
111
|
+
}
|
|
112
|
+
return loader.load(key);
|
|
113
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBunSqlAvailable = isBunSqlAvailable;
|
|
4
|
+
exports.createSqlClient = createSqlClient;
|
|
5
|
+
exports.createBunSqlClient = createBunSqlClient;
|
|
6
|
+
exports.wrapPgPoolAsSqlClient = wrapPgPoolAsSqlClient;
|
|
7
|
+
exports.wrapMysqlPoolAsSqlClient = wrapMysqlPoolAsSqlClient;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const promise_1 = require("mysql2/promise");
|
|
10
|
+
const node_sqlite_1 = require("node:sqlite");
|
|
11
|
+
const pg_1 = tslib_1.__importDefault(require("pg"));
|
|
12
|
+
const adapter_js_1 = require("./adapter.js");
|
|
13
|
+
const uri_js_1 = require("./uri.js");
|
|
14
|
+
function getBunSqlCtor() {
|
|
15
|
+
const bun = globalThis.Bun;
|
|
16
|
+
return typeof bun?.SQL === 'function' ? bun.SQL : undefined;
|
|
17
|
+
}
|
|
18
|
+
function isBunSqlAvailable() {
|
|
19
|
+
return getBunSqlCtor() != null;
|
|
20
|
+
}
|
|
21
|
+
function createSqlClient(opts) {
|
|
22
|
+
if (!opts.preferNode && isBunSqlAvailable()) {
|
|
23
|
+
return createBunSqlClient(opts);
|
|
24
|
+
}
|
|
25
|
+
switch (opts.adapter) {
|
|
26
|
+
case 'sqlite':
|
|
27
|
+
return createSqliteClient(opts.location, opts.cwd);
|
|
28
|
+
case 'mysql':
|
|
29
|
+
return createMysqlClient(opts);
|
|
30
|
+
case 'postgres':
|
|
31
|
+
return createPostgresClient(opts);
|
|
32
|
+
default:
|
|
33
|
+
throw new Error(`Unknown SQL adapter: ${opts.adapter}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wrap Bun's native `SQL` client when running under Bun.
|
|
38
|
+
* Uses `sql.unsafe(query, params)` so our adapter placeholders (`$1` / `?`) work as-is.
|
|
39
|
+
*/
|
|
40
|
+
function createBunSqlClient(opts) {
|
|
41
|
+
const BunSQL = getBunSqlCtor();
|
|
42
|
+
if (!BunSQL) {
|
|
43
|
+
throw new Error('Bun.SQL is not available in this runtime');
|
|
44
|
+
}
|
|
45
|
+
const bunOpts = {
|
|
46
|
+
adapter: opts.adapter === 'mysql' ? 'mysql' : opts.adapter,
|
|
47
|
+
};
|
|
48
|
+
if (opts.max != null)
|
|
49
|
+
bunOpts.max = opts.max;
|
|
50
|
+
if (opts.idleTimeout != null)
|
|
51
|
+
bunOpts.idleTimeout = opts.idleTimeout;
|
|
52
|
+
if (opts.connectionTimeout != null)
|
|
53
|
+
bunOpts.connectionTimeout = opts.connectionTimeout;
|
|
54
|
+
if (opts.tls != null)
|
|
55
|
+
bunOpts.tls = opts.tls === 'true' ? true : opts.tls;
|
|
56
|
+
const sql = new BunSQL(opts.location, bunOpts);
|
|
57
|
+
return {
|
|
58
|
+
adapter: opts.adapter,
|
|
59
|
+
async query(query, params = []) {
|
|
60
|
+
const result = await sql.unsafe(query, params);
|
|
61
|
+
const rows = normalizeBunRows(result);
|
|
62
|
+
const rowCount = typeof result?.count === 'number'
|
|
63
|
+
? result.count
|
|
64
|
+
: typeof result?.affectedRows === 'number'
|
|
65
|
+
? result.affectedRows
|
|
66
|
+
: rows.length;
|
|
67
|
+
return { rows, rowCount };
|
|
68
|
+
},
|
|
69
|
+
async dispose() {
|
|
70
|
+
if (typeof sql.close === 'function') {
|
|
71
|
+
await sql.close();
|
|
72
|
+
}
|
|
73
|
+
else if (typeof sql.end === 'function') {
|
|
74
|
+
await sql.end();
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function normalizeBunRows(result) {
|
|
80
|
+
if (result == null)
|
|
81
|
+
return [];
|
|
82
|
+
// Copy into a plain array — Bun results are array-like and may carry extra props (`count`).
|
|
83
|
+
if (typeof result.length === 'number') {
|
|
84
|
+
return Array.from({ length: result.length }, (_, i) => result[i]);
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(result)) {
|
|
87
|
+
return [...result];
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Wrap an existing `pg.Pool` (or compatible) as SqlClient.
|
|
93
|
+
*/
|
|
94
|
+
function wrapPgPoolAsSqlClient(pool) {
|
|
95
|
+
const client = {
|
|
96
|
+
adapter: 'postgres',
|
|
97
|
+
// Expose real pg.Pool when present for `@dataplan/pg`.
|
|
98
|
+
pgPool: 'connect' in pool ? pool : undefined,
|
|
99
|
+
async query(sql, params = []) {
|
|
100
|
+
const result = await pool.query(sql, params);
|
|
101
|
+
return {
|
|
102
|
+
rows: (result.rows || []),
|
|
103
|
+
rowCount: Number(result.rowCount ?? result.rows?.length ?? 0),
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
async dispose() {
|
|
107
|
+
if (typeof pool.end === 'function') {
|
|
108
|
+
await pool.end();
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
return client;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Wrap an existing `mysql` / `mysql2` pool (legacy handler `pool` config) as SqlClient.
|
|
116
|
+
*/
|
|
117
|
+
function wrapMysqlPoolAsSqlClient(pool) {
|
|
118
|
+
// mysql (non-promise) exposes .promise(); mysql2/promise is already thenable
|
|
119
|
+
const p = typeof pool.promise === 'function' ? pool.promise() : pool;
|
|
120
|
+
return {
|
|
121
|
+
adapter: 'mysql',
|
|
122
|
+
async query(sql, params = []) {
|
|
123
|
+
const [result] = await p.query(sql, params);
|
|
124
|
+
if (Array.isArray(result)) {
|
|
125
|
+
return { rows: result, rowCount: result.length };
|
|
126
|
+
}
|
|
127
|
+
const header = result;
|
|
128
|
+
return { rows: [], rowCount: Number(header.affectedRows ?? 0) };
|
|
129
|
+
},
|
|
130
|
+
async dispose() {
|
|
131
|
+
if (typeof p.end === 'function') {
|
|
132
|
+
await p.end();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function createSqliteClient(location, cwd) {
|
|
138
|
+
const dbPath = (0, adapter_js_1.resolveSqlitePath)(location, cwd);
|
|
139
|
+
const db = new node_sqlite_1.DatabaseSync(dbPath);
|
|
140
|
+
return {
|
|
141
|
+
adapter: 'sqlite',
|
|
142
|
+
async query(sql, params = []) {
|
|
143
|
+
const stmt = db.prepare(sql);
|
|
144
|
+
const bind = params;
|
|
145
|
+
const returnsRows = /^\s*(SELECT|PRAGMA|WITH)\b/i.test(sql) || /\bRETURNING\b/i.test(sql);
|
|
146
|
+
if (returnsRows) {
|
|
147
|
+
const rows = stmt.all(...bind);
|
|
148
|
+
return { rows, rowCount: rows.length };
|
|
149
|
+
}
|
|
150
|
+
const result = stmt.run(...bind);
|
|
151
|
+
return {
|
|
152
|
+
rows: [],
|
|
153
|
+
rowCount: Number(result.changes ?? 0),
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
dispose() {
|
|
157
|
+
db.close();
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function createMysqlClient(opts) {
|
|
162
|
+
const parsed = (0, uri_js_1.parseSqlUri)(opts.location);
|
|
163
|
+
if (parsed.adapter !== 'mysql') {
|
|
164
|
+
throw new Error(`Expected mysql URI, got ${parsed.adapter}`);
|
|
165
|
+
}
|
|
166
|
+
const tls = resolveTlsFlag(opts.tls, parsed.ssl);
|
|
167
|
+
const pool = (0, promise_1.createPool)({
|
|
168
|
+
host: parsed.host,
|
|
169
|
+
port: parsed.port,
|
|
170
|
+
user: parsed.user,
|
|
171
|
+
password: parsed.password,
|
|
172
|
+
database: parsed.database,
|
|
173
|
+
ssl: tls ? { rejectUnauthorized: false } : undefined,
|
|
174
|
+
supportBigNumbers: true,
|
|
175
|
+
bigNumberStrings: true,
|
|
176
|
+
connectionLimit: opts.max ?? 10,
|
|
177
|
+
idleTimeout: opts.idleTimeout != null ? opts.idleTimeout * 1000 : undefined,
|
|
178
|
+
connectTimeout: opts.connectionTimeout != null ? opts.connectionTimeout * 1000 : undefined,
|
|
179
|
+
});
|
|
180
|
+
return wrapMysqlPoolAsSqlClient(pool);
|
|
181
|
+
}
|
|
182
|
+
function createPostgresClient(opts) {
|
|
183
|
+
const parsed = (0, uri_js_1.parseSqlUri)(opts.location);
|
|
184
|
+
if (parsed.adapter !== 'postgres') {
|
|
185
|
+
throw new Error(`Expected postgres URI, got ${parsed.adapter}`);
|
|
186
|
+
}
|
|
187
|
+
const tls = resolveTlsFlag(opts.tls, parsed.ssl);
|
|
188
|
+
const pool = new pg_1.default.Pool({
|
|
189
|
+
connectionString: opts.location,
|
|
190
|
+
max: opts.max ?? 10,
|
|
191
|
+
idleTimeoutMillis: opts.idleTimeout != null ? opts.idleTimeout * 1000 : undefined,
|
|
192
|
+
connectionTimeoutMillis: opts.connectionTimeout != null ? opts.connectionTimeout * 1000 : undefined,
|
|
193
|
+
ssl: tls ? { rejectUnauthorized: false } : undefined,
|
|
194
|
+
});
|
|
195
|
+
return wrapPgPoolAsSqlClient(pool);
|
|
196
|
+
}
|
|
197
|
+
function resolveTlsFlag(option, fromUri) {
|
|
198
|
+
if (option === false || option === 'disable')
|
|
199
|
+
return false;
|
|
200
|
+
if (option === true || option === 'true')
|
|
201
|
+
return true;
|
|
202
|
+
if (typeof option === 'string' && option.length > 0 && option !== 'false')
|
|
203
|
+
return true;
|
|
204
|
+
return Boolean(fromUri);
|
|
205
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["import { DatabaseSync } from 'node:sqlite';\nimport { resolveSqlitePath } from './dialect.js';\nimport type { SqlClient, SqlDialect } from './types.js';\n\nexport interface CreateSqlClientOptions {\n dialect: SqlDialect;\n location: string;\n cwd?: string;\n}\n\nexport function createSqlClient(opts: CreateSqlClientOptions): SqlClient {\n switch (opts.dialect) {\n case 'sqlite':\n return createSqliteClient(opts.location, opts.cwd);\n case 'postgres':\n throw new Error(\n 'Postgres SQL transport dialect is not implemented yet in this PR (sqlite first).',\n );\n case 'mysql':\n throw new Error(\n 'MySQL SQL transport dialect is not implemented yet in this PR (sqlite first).',\n );\n default:\n throw new Error(`Unknown SQL dialect: ${opts.dialect as string}`);\n }\n}\n\nfunction createSqliteClient(location: string, cwd?: string): SqlClient {\n const dbPath = resolveSqlitePath(location, cwd);\n const db = new DatabaseSync(dbPath);\n return {\n dialect: 'sqlite',\n async query<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {\n const stmt = db.prepare(sql);\n const returnsRows =\n /^\\s*(SELECT|PRAGMA|WITH)\\b/i.test(sql) || /\\bRETURNING\\b/i.test(sql);\n if (returnsRows) {\n const rows = stmt.all(...params) as T[];\n return { rows, rowCount: rows.length };\n }\n const result = stmt.run(...params) as { changes?: number };\n return {\n rows: [] as T[],\n rowCount: Number(result.changes ?? 0),\n };\n },\n dispose() {\n db.close();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA6B;AAC7B,qBAAkC;AAS3B,SAAS,gBAAgB,MAAyC;AACvE,UAAQ,KAAK,SAAS;AAAA,IACpB,KAAK;AACH,aAAO,mBAAmB,KAAK,UAAU,KAAK,GAAG;AAAA,IACnD,KAAK;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF,KAAK;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACE,YAAM,IAAI,MAAM,wBAAwB,KAAK,OAAiB,EAAE;AAAA,EACpE;AACF;AAEA,SAAS,mBAAmB,UAAkB,KAAyB;AACrE,QAAM,aAAS,kCAAkB,UAAU,GAAG;AAC9C,QAAM,KAAK,IAAI,gCAAa,MAAM;AAClC,SAAO;AAAA,IACL,SAAS;AAAA,IACT,MAAM,MAAmC,KAAa,SAAoB,CAAC,GAAG;AAC5E,YAAM,OAAO,GAAG,QAAQ,GAAG;AAC3B,YAAM,cACJ,8BAA8B,KAAK,GAAG,KAAK,iBAAiB,KAAK,GAAG;AACtE,UAAI,aAAa;AACf,cAAM,OAAO,KAAK,IAAI,GAAG,MAAM;AAC/B,eAAO,EAAE,MAAM,UAAU,KAAK,OAAO;AAAA,MACvC;AACA,YAAM,SAAS,KAAK,IAAI,GAAG,MAAM;AACjC,aAAO;AAAA,QACL,MAAM,CAAC;AAAA,QACP,UAAU,OAAO,OAAO,WAAW,CAAC;AAAA,MACtC;AAAA,IACF;AAAA,IACA,UAAU;AACR,SAAG,MAAM;AAAA,IACX;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferDialectFromLocation = inferDialectFromLocation;
|
|
4
|
+
exports.quoteIdent = quoteIdent;
|
|
5
|
+
exports.placeholder = placeholder;
|
|
6
|
+
exports.resolveSqlitePath = resolveSqlitePath;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const uri_js_1 = require("./uri.js");
|
|
9
|
+
/**
|
|
10
|
+
* Infer dialect from a transport `location` / connection URI.
|
|
11
|
+
* Prefer {@link inferDialectFromConnectionString} for full Bun-compatible rules.
|
|
12
|
+
*/
|
|
13
|
+
function inferDialectFromLocation(location) {
|
|
14
|
+
if (!location)
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
return (0, uri_js_1.inferDialectFromConnectionString)(location);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function quoteIdent(dialect, name) {
|
|
24
|
+
switch (dialect) {
|
|
25
|
+
case 'mysql':
|
|
26
|
+
return `\`${name.replace(/`/g, '``')}\``;
|
|
27
|
+
case 'postgres':
|
|
28
|
+
case 'sqlite':
|
|
29
|
+
default:
|
|
30
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function placeholder(dialect, index) {
|
|
34
|
+
// index is 1-based for postgres
|
|
35
|
+
if (dialect === 'postgres') {
|
|
36
|
+
return `$${index}`;
|
|
37
|
+
}
|
|
38
|
+
return '?';
|
|
39
|
+
}
|
|
40
|
+
function resolveSqlitePath(location, cwd) {
|
|
41
|
+
let path = location;
|
|
42
|
+
if (path.startsWith('file:')) {
|
|
43
|
+
path = path.slice('file:'.length);
|
|
44
|
+
}
|
|
45
|
+
else if (path.toLowerCase().startsWith('sqlite:')) {
|
|
46
|
+
path = path.slice(path.indexOf(':') + 1);
|
|
47
|
+
}
|
|
48
|
+
if (path.startsWith('//')) {
|
|
49
|
+
// file://absolute or file:///absolute
|
|
50
|
+
path = path.replace(/^\/\/+/, '/');
|
|
51
|
+
}
|
|
52
|
+
const qIdx = path.indexOf('?');
|
|
53
|
+
if (qIdx !== -1) {
|
|
54
|
+
path = path.slice(0, qIdx);
|
|
55
|
+
}
|
|
56
|
+
if (!(0, node_path_1.isAbsolute)(path) && cwd && path !== ':memory:') {
|
|
57
|
+
return (0, node_path_1.join)(cwd, path);
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dialect.ts"],
|
|
4
|
+
"sourcesContent": ["import { join as pathJoin, isAbsolute as pathIsAbsolute } from 'node:path';\nimport type { SqlDialect } from './types.js';\n\nexport function inferDialectFromLocation(location: string | undefined): SqlDialect | undefined {\n if (!location) return undefined;\n const lower = location.toLowerCase();\n if (lower.startsWith('postgres://') || lower.startsWith('postgresql://')) {\n return 'postgres';\n }\n if (lower.startsWith('mysql://') || lower.startsWith('mysqls://')) {\n return 'mysql';\n }\n if (\n lower.startsWith('file:') ||\n lower.startsWith('sqlite:') ||\n lower.endsWith('.db') ||\n lower.endsWith('.sqlite') ||\n lower.endsWith('.sqlite3')\n ) {\n return 'sqlite';\n }\n return undefined;\n}\n\nexport function quoteIdent(dialect: SqlDialect, name: string): string {\n switch (dialect) {\n case 'mysql':\n return `\\`${name.replace(/`/g, '``')}\\``;\n case 'postgres':\n case 'sqlite':\n default:\n return `\"${name.replace(/\"/g, '\"\"')}\"`;\n }\n}\n\nexport function placeholder(dialect: SqlDialect, index: number): string {\n // index is 1-based for postgres\n if (dialect === 'postgres') {\n return `$${index}`;\n }\n return '?';\n}\n\nexport function resolveSqlitePath(location: string, cwd?: string): string {\n let path = location;\n if (path.startsWith('file:')) {\n path = path.slice('file:'.length);\n } else if (path.startsWith('sqlite:')) {\n path = path.slice('sqlite:'.length);\n }\n if (path.startsWith('//')) {\n // file://absolute or file:///absolute\n path = path.replace(/^\\/\\/+/, '/');\n }\n if (!pathIsAbsolute(path) && cwd) {\n return pathJoin(cwd, path);\n }\n return path;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA+D;AAGxD,SAAS,yBAAyB,UAAsD;AAC7F,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,QAAQ,SAAS,YAAY;AACnC,MAAI,MAAM,WAAW,aAAa,KAAK,MAAM,WAAW,eAAe,GAAG;AACxE,WAAO;AAAA,EACT;AACA,MAAI,MAAM,WAAW,UAAU,KAAK,MAAM,WAAW,WAAW,GAAG;AACjE,WAAO;AAAA,EACT;AACA,MACE,MAAM,WAAW,OAAO,KACxB,MAAM,WAAW,SAAS,KAC1B,MAAM,SAAS,KAAK,KACpB,MAAM,SAAS,SAAS,KACxB,MAAM,SAAS,UAAU,GACzB;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,SAAqB,MAAsB;AACpE,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO,KAAK,KAAK,QAAQ,MAAM,IAAI,CAAC;AAAA,IACtC,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACE,aAAO,IAAI,KAAK,QAAQ,MAAM,IAAI,CAAC;AAAA,EACvC;AACF;AAEO,SAAS,YAAY,SAAqB,OAAuB;AAEtE,MAAI,YAAY,YAAY;AAC1B,WAAO,IAAI,KAAK;AAAA,EAClB;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB,UAAkB,KAAsB;AACxE,MAAI,OAAO;AACX,MAAI,KAAK,WAAW,OAAO,GAAG;AAC5B,WAAO,KAAK,MAAM,QAAQ,MAAM;AAAA,EAClC,WAAW,KAAK,WAAW,SAAS,GAAG;AACrC,WAAO,KAAK,MAAM,UAAU,MAAM;AAAA,EACpC;AACA,MAAI,KAAK,WAAW,IAAI,GAAG;AAEzB,WAAO,KAAK,QAAQ,UAAU,GAAG;AAAA,EACnC;AACA,MAAI,KAAC,iBAAAA,YAAe,IAAI,KAAK,KAAK;AAChC,eAAO,iBAAAC,MAAS,KAAK,IAAI;AAAA,EAC3B;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["pathIsAbsolute", "pathJoin"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setTypeResolveReference = setTypeResolveReference;
|
|
4
|
+
exports.getTypeResolveReference = getTypeResolveReference;
|
|
5
|
+
exports.getSqlDirectiveArgs = getSqlDirectiveArgs;
|
|
6
|
+
exports.wireSqlEntityResolvers = wireSqlEntityResolvers;
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
8
|
+
const subgraph_1 = require("@apollo/subgraph");
|
|
9
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
10
|
+
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
11
|
+
/**
|
|
12
|
+
* Record `__resolveReference` the way `@apollo/subgraph` expects
|
|
13
|
+
* (`extensions.apollo.subgraph.resolveReference`) so we can reuse
|
|
14
|
+
* `entitiesResolver` instead of maintaining our own `_entities` dispatch.
|
|
15
|
+
* Also mirror on `type.resolveReference` for Hive stub hydration helpers / tests.
|
|
16
|
+
*/
|
|
17
|
+
function setTypeResolveReference(type, resolveReference) {
|
|
18
|
+
const extensions = (type.extensions ??= {});
|
|
19
|
+
const apollo = (extensions.apollo ??= {});
|
|
20
|
+
const subgraph = (apollo.subgraph ??= {});
|
|
21
|
+
subgraph.resolveReference = resolveReference;
|
|
22
|
+
type.resolveReference = resolveReference;
|
|
23
|
+
}
|
|
24
|
+
function getTypeResolveReference(type) {
|
|
25
|
+
const fromExtensions = type.extensions?.apollo?.subgraph?.resolveReference;
|
|
26
|
+
if (typeof fromExtensions === 'function') {
|
|
27
|
+
return fromExtensions;
|
|
28
|
+
}
|
|
29
|
+
const fromType = type.resolveReference;
|
|
30
|
+
return typeof fromType === 'function' ? fromType : undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Raw `@sql` plus composed `@join__directive(name: "sql")` payloads. */
|
|
33
|
+
function getSqlDirectiveArgs(schema, node) {
|
|
34
|
+
const fromDef = (0, utils_1.getDefDirectives)(schema, node)
|
|
35
|
+
.filter(d => d.name === 'sql')
|
|
36
|
+
.map(d => d.args || {});
|
|
37
|
+
const joins = node.extensions?.directives?.join__directive;
|
|
38
|
+
const fromJoin = [];
|
|
39
|
+
if (Array.isArray(joins)) {
|
|
40
|
+
for (const join of joins) {
|
|
41
|
+
if (join?.name === 'sql' && join.args && typeof join.args === 'object') {
|
|
42
|
+
fromJoin.push(join.args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const rootJoins = node.extensions?.join__directive;
|
|
47
|
+
if (Array.isArray(rootJoins)) {
|
|
48
|
+
for (const join of rootJoins) {
|
|
49
|
+
if (join?.name === 'sql' && join.args && typeof join.args === 'object') {
|
|
50
|
+
fromJoin.push(join.args);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [...fromDef, ...fromJoin];
|
|
55
|
+
}
|
|
56
|
+
const MESH_ENTITY_FILL = Symbol.for('mesh.sql.entityFill');
|
|
57
|
+
/**
|
|
58
|
+
* For types with `resolveReference`, resolve missing fields by fetching the entity
|
|
59
|
+
* once per parent object (deduped). Lets Hive honor entity stubs the way Router does.
|
|
60
|
+
*/
|
|
61
|
+
function hydrateEntityStubFieldResolvers(schema) {
|
|
62
|
+
for (const type of Object.values(schema.getTypeMap())) {
|
|
63
|
+
if (!(0, graphql_1.isObjectType)(type) || type.name.startsWith('__')) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const resolveReference = getTypeResolveReference(type);
|
|
67
|
+
if (!resolveReference) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const fields = type.getFields();
|
|
71
|
+
for (const fieldName of Object.keys(fields)) {
|
|
72
|
+
const field = fields[fieldName];
|
|
73
|
+
if (typeof field.resolve === 'function') {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
field.resolve = (parent, _args, context, info) => {
|
|
77
|
+
if (parent == null || typeof parent !== 'object') {
|
|
78
|
+
return parent?.[fieldName];
|
|
79
|
+
}
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(parent, fieldName)) {
|
|
81
|
+
return parent[fieldName];
|
|
82
|
+
}
|
|
83
|
+
let fill = parent[MESH_ENTITY_FILL];
|
|
84
|
+
if (!fill) {
|
|
85
|
+
fill = (0, promise_helpers_1.fakePromise)(resolveReference(parent, context, info)).then((full) => {
|
|
86
|
+
if (full && typeof full === 'object') {
|
|
87
|
+
Object.assign(parent, full);
|
|
88
|
+
}
|
|
89
|
+
return parent;
|
|
90
|
+
});
|
|
91
|
+
parent[MESH_ENTITY_FILL] = fill;
|
|
92
|
+
}
|
|
93
|
+
return fill.then((full) => full?.[fieldName]);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Add / repair Federation `Query._entities` (same contract as Connectors REST transport).
|
|
100
|
+
*/
|
|
101
|
+
function ensureFederationEntitiesField(schema) {
|
|
102
|
+
const queryType = schema.getQueryType();
|
|
103
|
+
if (!queryType) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const queryFields = queryType.getFields();
|
|
107
|
+
const entityTypes = Object.values(schema.getTypeMap()).filter((t) => (0, graphql_1.isObjectType)(t) && !t.name.startsWith('__') && !!getTypeResolveReference(t));
|
|
108
|
+
if (!entityTypes.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const typeMap = schema.getTypeMap();
|
|
112
|
+
let anyType = typeMap._Any;
|
|
113
|
+
if (!anyType) {
|
|
114
|
+
anyType = new graphql_1.GraphQLScalarType({
|
|
115
|
+
name: '_Any',
|
|
116
|
+
serialize: value => value,
|
|
117
|
+
parseValue: value => value,
|
|
118
|
+
});
|
|
119
|
+
typeMap._Any = anyType;
|
|
120
|
+
}
|
|
121
|
+
let entityUnion = typeMap._Entity;
|
|
122
|
+
if (!entityUnion) {
|
|
123
|
+
entityUnion = new graphql_1.GraphQLUnionType({
|
|
124
|
+
name: '_Entity',
|
|
125
|
+
types: entityTypes,
|
|
126
|
+
resolveType(obj) {
|
|
127
|
+
return obj?.__typename || undefined;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
typeMap._Entity = entityUnion;
|
|
131
|
+
}
|
|
132
|
+
const entitiesResolve = (_root, args, context, info) => {
|
|
133
|
+
const representations = args?.representations;
|
|
134
|
+
if (!Array.isArray(representations)) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
return (0, subgraph_1.entitiesResolver)({ representations, context, info });
|
|
138
|
+
};
|
|
139
|
+
if (queryFields._entities) {
|
|
140
|
+
queryFields._entities.resolve = entitiesResolve;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
queryFields._entities = {
|
|
144
|
+
name: '_entities',
|
|
145
|
+
description: 'Federation entity resolver for SQL transport (Hive `_entities` path)',
|
|
146
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(entityUnion)),
|
|
147
|
+
args: [
|
|
148
|
+
{
|
|
149
|
+
name: 'representations',
|
|
150
|
+
description: undefined,
|
|
151
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(anyType))),
|
|
152
|
+
defaultValue: undefined,
|
|
153
|
+
deprecationReason: undefined,
|
|
154
|
+
extensions: {},
|
|
155
|
+
astNode: undefined,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
resolve: entitiesResolve,
|
|
159
|
+
deprecationReason: undefined,
|
|
160
|
+
extensions: {},
|
|
161
|
+
astNode: undefined,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Wire Federation entity resolution from type-level `@sql` (Connectors type-level pattern).
|
|
166
|
+
* Query `entity: true` is no longer used — presence of OBJECT `@sql` is the signal.
|
|
167
|
+
*/
|
|
168
|
+
function wireSqlEntityResolvers(schema, opts) {
|
|
169
|
+
for (const type of Object.values(schema.getTypeMap())) {
|
|
170
|
+
if (!(0, graphql_1.isObjectType)(type) || type.name.startsWith('__'))
|
|
171
|
+
continue;
|
|
172
|
+
if (getTypeResolveReference(type))
|
|
173
|
+
continue;
|
|
174
|
+
const sqlArgsList = getSqlDirectiveArgs(schema, type);
|
|
175
|
+
if (!sqlArgsList.length)
|
|
176
|
+
continue;
|
|
177
|
+
const sqlArgs = sqlArgsList[0];
|
|
178
|
+
const kind = sqlArgs.kind || 'ROW';
|
|
179
|
+
if (kind !== 'ROW')
|
|
180
|
+
continue;
|
|
181
|
+
setTypeResolveReference(type, (reference, context, info) => opts.executeTypeLevelRow(sqlArgs, reference, context, info));
|
|
182
|
+
}
|
|
183
|
+
ensureFederationEntitiesField(schema);
|
|
184
|
+
hydrateEntityStubFieldResolvers(schema);
|
|
185
|
+
return schema;
|
|
186
|
+
}
|