@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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/sql-builder.ts"],
|
|
4
|
+
"sourcesContent": ["import { columnMapFromSelection, parseSqlMapping, resolveMappingValue } from './mapping.js';\nimport { placeholder, quoteIdent } from './dialect.js';\nimport type { ParsedSqlMapping, SqlDialect, SqlMappingEntry, SqlQueryKind } from './types.js';\n\nexport interface BuiltQuery {\n sql: string;\n params: unknown[];\n}\n\nexport interface SelectPlan {\n table: string;\n kind: SqlQueryKind;\n selection: ParsedSqlMapping;\n argsMapping: ParsedSqlMapping;\n graphqlArgs: Record<string, any>;\n parent?: Record<string, any>;\n}\n\nconst PLANNER_KEYS = new Set([\n 'filter',\n 'orderBy',\n 'first',\n 'after',\n 'last',\n 'before',\n 'limit',\n 'offset',\n 'set',\n 'where',\n]);\n\nexport function buildSelect(dialect: SqlDialect, plan: SelectPlan): BuiltQuery {\n const columns = columnMapFromSelection(plan.selection);\n const selectCols =\n columns.size === 0\n ? ['*']\n : [...new Set(columns.values())].map(c => quoteIdent(dialect, c));\n\n const params: unknown[] = [];\n const whereParts: string[] = [];\n\n // Equality / join predicates from args mapping (non-planner keys)\n for (const entry of plan.argsMapping.entries) {\n if (PLANNER_KEYS.has(entry.key) || entry.children) {\n continue;\n }\n const resolved = resolveMappingValue(entry.value, {\n args: plan.graphqlArgs,\n parent: plan.parent,\n });\n if (resolved === undefined) continue;\n params.push(resolved);\n whereParts.push(\n `${quoteIdent(dialect, entry.key)} = ${placeholder(dialect, params.length)}`,\n );\n }\n\n // filter: $args.filter\n const filterEntry = plan.argsMapping.entries.find(e => e.key === 'filter');\n if (filterEntry) {\n const filterVal = resolveMappingValue(filterEntry.value, {\n args: plan.graphqlArgs,\n parent: plan.parent,\n });\n if (filterVal && typeof filterVal === 'object') {\n appendFilter(dialect, filterVal as Record<string, any>, columns, whereParts, params);\n }\n }\n\n // Also accept direct graphqlArgs.filter when mapping omitted the binder but arg exists\n if (!filterEntry && plan.graphqlArgs.filter) {\n appendFilter(dialect, plan.graphqlArgs.filter, columns, whereParts, params);\n }\n\n let sql = `SELECT ${selectCols.join(', ')} FROM ${quoteIdent(dialect, plan.table)}`;\n if (whereParts.length) {\n sql += ` WHERE ${whereParts.join(' AND ')}`;\n }\n\n if (plan.kind === 'COUNT') {\n sql = `SELECT COUNT(*) AS ${quoteIdent(dialect, 'count')} FROM ${quoteIdent(dialect, plan.table)}`;\n if (whereParts.length) {\n sql += ` WHERE ${whereParts.join(' AND ')}`;\n }\n return { sql, params };\n }\n\n const orderBy = resolvePlannerArg(plan, 'orderBy') as string[] | string | undefined;\n const orderSql = buildOrderBy(dialect, orderBy, columns);\n if (orderSql) {\n sql += ` ORDER BY ${orderSql}`;\n }\n\n if (plan.kind === 'CONNECTION') {\n const first = Number(resolvePlannerArg(plan, 'first') ?? 10);\n const after = resolvePlannerArg(plan, 'after');\n // Cursor = offset for phase 1 (opaque base64 of offset)\n let offset = 0;\n if (typeof after === 'string' && after.length) {\n offset = decodeCursor(after);\n }\n const limit = Math.max(0, first);\n // fetch one extra to detect hasNextPage\n params.push(limit + 1);\n sql += ` LIMIT ${placeholder(dialect, params.length)}`;\n params.push(offset);\n sql += ` OFFSET ${placeholder(dialect, params.length)}`;\n return { sql, params };\n }\n\n const limit = resolvePlannerArg(plan, 'limit');\n const offset = resolvePlannerArg(plan, 'offset');\n if (limit != null) {\n params.push(Number(limit));\n sql += ` LIMIT ${placeholder(dialect, params.length)}`;\n } else if (plan.kind === 'ROW') {\n params.push(1);\n sql += ` LIMIT ${placeholder(dialect, params.length)}`;\n }\n if (offset != null) {\n params.push(Number(offset));\n sql += ` OFFSET ${placeholder(dialect, params.length)}`;\n }\n\n return { sql, params };\n}\n\nexport function buildInsert(\n dialect: SqlDialect,\n table: string,\n argsMapping: ParsedSqlMapping,\n graphqlArgs: Record<string, any>,\n returningColumns: string[],\n): BuiltQuery {\n const cols: string[] = [];\n const params: unknown[] = [];\n for (const entry of argsMapping.entries) {\n if (entry.key === 'set' || entry.key === 'where' || entry.children) continue;\n const val = resolveMappingValue(entry.value, { args: graphqlArgs });\n if (val === undefined) continue;\n cols.push(entry.key);\n params.push(val);\n }\n if (!cols.length) {\n throw new Error(`@sql__mutation INSERT on ${table} has no column values`);\n }\n const colSql = cols.map(c => quoteIdent(dialect, c)).join(', ');\n const ph = cols.map((_, i) => placeholder(dialect, i + 1)).join(', ');\n let sql = `INSERT INTO ${quoteIdent(dialect, table)} (${colSql}) VALUES (${ph})`;\n if (returningColumns.length && (dialect === 'postgres' || dialect === 'sqlite')) {\n sql += ` RETURNING ${returningColumns.map(c => quoteIdent(dialect, c)).join(', ')}`;\n }\n return { sql, params };\n}\n\nexport function buildUpdate(\n dialect: SqlDialect,\n table: string,\n argsMapping: ParsedSqlMapping,\n graphqlArgs: Record<string, any>,\n returningColumns: string[],\n): BuiltQuery {\n const setBlock = argsMapping.entries.find(e => e.key === 'set');\n const whereBlock = argsMapping.entries.find(e => e.key === 'where');\n const setEntries = setBlock?.children || [];\n const whereEntries = whereBlock?.children || argsMapping.entries.filter(e => e.key !== 'set');\n\n const params: unknown[] = [];\n const sets: string[] = [];\n for (const entry of setEntries) {\n const val = resolveMappingValue(entry.value, { args: graphqlArgs });\n if (val === undefined) continue;\n params.push(val);\n sets.push(`${quoteIdent(dialect, entry.key)} = ${placeholder(dialect, params.length)}`);\n }\n if (!sets.length) {\n throw new Error(`@sql__mutation UPDATE on ${table} has no SET columns`);\n }\n const whereParts: string[] = [];\n for (const entry of whereEntries) {\n if (entry.key === 'set' || entry.children) continue;\n const val = resolveMappingValue(entry.value, { args: graphqlArgs });\n if (val === undefined) continue;\n params.push(val);\n whereParts.push(\n `${quoteIdent(dialect, entry.key)} = ${placeholder(dialect, params.length)}`,\n );\n }\n let sql = `UPDATE ${quoteIdent(dialect, table)} SET ${sets.join(', ')}`;\n if (whereParts.length) {\n sql += ` WHERE ${whereParts.join(' AND ')}`;\n }\n if (returningColumns.length && (dialect === 'postgres' || dialect === 'sqlite')) {\n sql += ` RETURNING ${returningColumns.map(c => quoteIdent(dialect, c)).join(', ')}`;\n }\n return { sql, params };\n}\n\nexport function buildDelete(\n dialect: SqlDialect,\n table: string,\n argsMapping: ParsedSqlMapping,\n graphqlArgs: Record<string, any>,\n): BuiltQuery {\n const whereBlock = argsMapping.entries.find(e => e.key === 'where');\n const whereEntries = whereBlock?.children || argsMapping.entries;\n const params: unknown[] = [];\n const whereParts: string[] = [];\n for (const entry of whereEntries) {\n if (entry.children) continue;\n const val = resolveMappingValue(entry.value, { args: graphqlArgs });\n if (val === undefined) continue;\n params.push(val);\n whereParts.push(\n `${quoteIdent(dialect, entry.key)} = ${placeholder(dialect, params.length)}`,\n );\n }\n let sql = `DELETE FROM ${quoteIdent(dialect, table)}`;\n if (whereParts.length) {\n sql += ` WHERE ${whereParts.join(' AND ')}`;\n }\n return { sql, params };\n}\n\nfunction resolvePlannerArg(plan: SelectPlan, key: string): unknown {\n const entry = plan.argsMapping.entries.find(e => e.key === key);\n if (entry) {\n return resolveMappingValue(entry.value, { args: plan.graphqlArgs, parent: plan.parent });\n }\n return plan.graphqlArgs[key];\n}\n\nfunction buildOrderBy(\n dialect: SqlDialect,\n orderBy: string[] | string | undefined,\n columns: Map<string, string>,\n): string {\n if (!orderBy) return '';\n const list = Array.isArray(orderBy) ? orderBy : [orderBy];\n const parts: string[] = [];\n for (const item of list) {\n if (typeof item !== 'string') continue;\n const desc = item.endsWith('_DESC');\n const asc = item.endsWith('_ASC');\n if (!asc && !desc) continue;\n const fieldConst = item.replace(/_DESC$|_ASC$/, '');\n const graphqlField = constToCamel(fieldConst);\n const col = columns.get(graphqlField) || columns.get(fieldConst.toLowerCase());\n if (!col) {\n // fall back: try id\n if (graphqlField === 'id') {\n const idCol = columns.get('id');\n if (idCol) {\n parts.push(`${quoteIdent(dialect, idCol)} ${desc ? 'DESC' : 'ASC'}`);\n }\n }\n continue;\n }\n parts.push(`${quoteIdent(dialect, col)} ${desc ? 'DESC' : 'ASC'}`);\n }\n return parts.join(', ');\n}\n\nfunction constToCamel(constant: string): string {\n const lower = constant.toLowerCase();\n return lower.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase());\n}\n\nfunction appendFilter(\n dialect: SqlDialect,\n filter: Record<string, any>,\n columns: Map<string, string>,\n whereParts: string[],\n params: unknown[],\n): void {\n if (!filter || typeof filter !== 'object') return;\n\n if (Array.isArray(filter.and)) {\n const parts: string[] = [];\n for (const sub of filter.and) {\n const inner: string[] = [];\n appendFilter(dialect, sub, columns, inner, params);\n if (inner.length) parts.push(`(${inner.join(' AND ')})`);\n }\n if (parts.length) whereParts.push(`(${parts.join(' AND ')})`);\n }\n if (Array.isArray(filter.or)) {\n const parts: string[] = [];\n for (const sub of filter.or) {\n const inner: string[] = [];\n appendFilter(dialect, sub, columns, inner, params);\n if (inner.length) parts.push(`(${inner.join(' AND ')})`);\n }\n if (parts.length) whereParts.push(`(${parts.join(' OR ')})`);\n }\n if (filter.not && typeof filter.not === 'object') {\n const inner: string[] = [];\n appendFilter(dialect, filter.not, columns, inner, params);\n if (inner.length) whereParts.push(`NOT (${inner.join(' AND ')})`);\n }\n\n for (const [field, ops] of Object.entries(filter)) {\n if (field === 'and' || field === 'or' || field === 'not') continue;\n if (ops == null || typeof ops !== 'object') continue;\n const col = columns.get(field);\n if (!col) continue;\n const q = quoteIdent(dialect, col);\n const o = ops as Record<string, any>;\n if ('eq' in o) {\n params.push(o.eq);\n whereParts.push(`${q} = ${placeholder(dialect, params.length)}`);\n }\n if ('ne' in o) {\n params.push(o.ne);\n whereParts.push(`${q} <> ${placeholder(dialect, params.length)}`);\n }\n if ('lt' in o) {\n params.push(o.lt);\n whereParts.push(`${q} < ${placeholder(dialect, params.length)}`);\n }\n if ('lte' in o) {\n params.push(o.lte);\n whereParts.push(`${q} <= ${placeholder(dialect, params.length)}`);\n }\n if ('gt' in o) {\n params.push(o.gt);\n whereParts.push(`${q} > ${placeholder(dialect, params.length)}`);\n }\n if ('gte' in o) {\n params.push(o.gte);\n whereParts.push(`${q} >= ${placeholder(dialect, params.length)}`);\n }\n if ('in' in o && Array.isArray(o.in)) {\n const phs = o.in.map((v: unknown) => {\n params.push(v);\n return placeholder(dialect, params.length);\n });\n whereParts.push(`${q} IN (${phs.join(', ')})`);\n }\n if ('nin' in o && Array.isArray(o.nin)) {\n const phs = o.nin.map((v: unknown) => {\n params.push(v);\n return placeholder(dialect, params.length);\n });\n whereParts.push(`${q} NOT IN (${phs.join(', ')})`);\n }\n if ('includes' in o) {\n params.push(`%${o.includes}%`);\n whereParts.push(`${q} LIKE ${placeholder(dialect, params.length)}`);\n }\n if ('startsWith' in o) {\n params.push(`${o.startsWith}%`);\n whereParts.push(`${q} LIKE ${placeholder(dialect, params.length)}`);\n }\n if ('endsWith' in o) {\n params.push(`%${o.endsWith}`);\n whereParts.push(`${q} LIKE ${placeholder(dialect, params.length)}`);\n }\n if ('isNull' in o) {\n whereParts.push(o.isNull ? `${q} IS NULL` : `${q} IS NOT NULL`);\n }\n }\n}\n\nexport function encodeCursor(offset: number): string {\n return Buffer.from(String(offset), 'utf8').toString('base64');\n}\n\nexport function decodeCursor(cursor: string): number {\n const n = Number(Buffer.from(cursor, 'base64').toString('utf8'));\n return Number.isFinite(n) ? n : 0;\n}\n\nexport function mapRowToGraphql(\n row: Record<string, unknown>,\n selection: ParsedSqlMapping,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const entry of selection.entries) {\n if (entry.children) continue;\n if (!entry.value || entry.value.kind !== 'column') continue;\n const raw = row[entry.value.value];\n out[entry.key] = raw != null && entry.key === 'id' ? String(raw) : raw;\n }\n return out;\n}\n\nexport function selectionHasNested(selection: ParsedSqlMapping, key: string): boolean {\n return selection.entries.some(e => e.key === key && e.children);\n}\n\nexport function nestedSelection(selection: ParsedSqlMapping, key: string): ParsedSqlMapping {\n const entry = selection.entries.find(e => e.key === key);\n return { entries: entry?.children || [] };\n}\n\nexport function collectReturningColumns(selection: ParsedSqlMapping): string[] {\n // Prefer nested payload object (album { ... })\n for (const entry of selection.entries) {\n if (entry.children?.length) {\n return [...columnMapFromSelection({ entries: entry.children }).values()];\n }\n }\n return [...columnMapFromSelection(selection).values()];\n}\n\nexport function parseArgsAndSelection(argsStr?: string | null, selectionStr?: string | null) {\n return {\n argsMapping: parseSqlMapping(argsStr),\n selection: parseSqlMapping(selectionStr),\n };\n}\n\nexport type { SqlMappingEntry };\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,wBAAwB,iBAAiB,2BAA2B;AAC7E,SAAS,aAAa,kBAAkB;AAiBxC,MAAM,eAAe,oBAAI,IAAI;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,SAAS,YAAY,SAAqB,MAA8B;AAC7E,QAAM,UAAU,uBAAuB,KAAK,SAAS;AACrD,QAAM,aACJ,QAAQ,SAAS,IACb,CAAC,GAAG,IACJ,CAAC,GAAG,IAAI,IAAI,QAAQ,OAAO,CAAC,CAAC,EAAE,IAAI,OAAK,WAAW,SAAS,CAAC,CAAC;AAEpE,QAAM,SAAoB,CAAC;AAC3B,QAAM,aAAuB,CAAC;AAG9B,aAAW,SAAS,KAAK,YAAY,SAAS;AAC5C,QAAI,aAAa,IAAI,MAAM,GAAG,KAAK,MAAM,UAAU;AACjD;AAAA,IACF;AACA,UAAM,WAAW,oBAAoB,MAAM,OAAO;AAAA,MAChD,MAAM,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,IACf,CAAC;AACD,QAAI,aAAa,OAAW;AAC5B,WAAO,KAAK,QAAQ;AACpB,eAAW;AAAA,MACT,GAAG,WAAW,SAAS,MAAM,GAAG,CAAC,MAAM,Y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AAQ,UAAU,QAAQ,KAAK,OAAK,EAAE,QAAQ,GAAG;AACvD,SAAO,EAAE,SAAS,OAAO,YAAY,CAAC,EAAE;AAC1C;AAEO,SAAS,wBAAwB,WAAuC;AAE7E,aAAW,SAAS,UAAU,SAAS;AACrC,QAAI,MAAM,UAAU,QAAQ;AAC1B,aAAO,CAAC,GAAG,uBAAuB,EAAE,SAAS,MAAM,SAAS,CAAC,EAAE,OAAO,CAAC;AAAA,IACzE;AAAA,EACF;AACA,SAAO,CAAC,GAAG,uBAAuB,SAAS,EAAE,OAAO,CAAC;AACvD;AAEO,SAAS,sBAAsB,SAAyB,cAA8B;AAC3F,SAAO;AAAA,IACL,aAAa,gBAAgB,OAAO;AAAA,IACpC,WAAW,gBAAgB,YAAY;AAAA,EACzC;AACF;",
|
|
6
|
+
"names": ["offset", "limit"]
|
|
7
|
+
}
|
|
File without changes
|
package/dist/esm/uri.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun-compatible connection URL env vars, in precedence order.
|
|
3
|
+
* @see https://bun.com/docs/runtime/sql
|
|
4
|
+
*/
|
|
5
|
+
export const SQL_URL_ENV_VARS = [
|
|
6
|
+
'DATABASE_URL',
|
|
7
|
+
'TLS_DATABASE_URL',
|
|
8
|
+
'POSTGRES_URL',
|
|
9
|
+
'PGURL',
|
|
10
|
+
'PG_URL',
|
|
11
|
+
'TLS_POSTGRES_DATABASE_URL',
|
|
12
|
+
'MYSQL_URL',
|
|
13
|
+
'TLS_MYSQL_DATABASE_URL',
|
|
14
|
+
'MARIADB_URL',
|
|
15
|
+
'TLS_MARIADB_DATABASE_URL',
|
|
16
|
+
'SQLITE_URL',
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a connection string from the environment the way Bun SQL does:
|
|
20
|
+
* URL vars first, then (when no URL) a postgres URL composed from `PG*` fields.
|
|
21
|
+
*
|
|
22
|
+
* `TLS_*` URLs get `sslmode=require` unless the URL already names an ssl mode.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveConnectionStringFromEnv(env = typeof process !== 'undefined' ? process.env : {}, opts) {
|
|
25
|
+
for (const key of SQL_URL_ENV_VARS) {
|
|
26
|
+
const value = env[key]?.trim();
|
|
27
|
+
if (!value)
|
|
28
|
+
continue;
|
|
29
|
+
if (opts?.adapter) {
|
|
30
|
+
try {
|
|
31
|
+
if (inferAdapterFromConnectionString(value) !== opts.adapter) {
|
|
32
|
+
// With an explicit adapter, skip URLs that name another adapter
|
|
33
|
+
// (Bun does the same when `adapter` is set).
|
|
34
|
+
if (key === 'DATABASE_URL' || key === 'TLS_DATABASE_URL')
|
|
35
|
+
continue;
|
|
36
|
+
if (opts.adapter === 'postgres' && !isPostgresUrlEnvKey(key))
|
|
37
|
+
continue;
|
|
38
|
+
if (opts.adapter === 'mysql' && !isMysqlUrlEnvKey(key))
|
|
39
|
+
continue;
|
|
40
|
+
if (opts.adapter === 'sqlite' && key !== 'SQLITE_URL')
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// unknown protocol — still return; caller / infer will throw
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (key.startsWith('TLS_')) {
|
|
49
|
+
return ensureSslModeRequire(value);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (opts?.adapter === 'mysql' || (!opts?.adapter && env.MYSQL_HOST)) {
|
|
54
|
+
const mysql = composeMysqlUrlFromEnv(env);
|
|
55
|
+
if (mysql)
|
|
56
|
+
return mysql;
|
|
57
|
+
}
|
|
58
|
+
if (opts?.adapter !== 'mysql' && opts?.adapter !== 'sqlite') {
|
|
59
|
+
const pg = composePostgresUrlFromEnv(env);
|
|
60
|
+
if (pg)
|
|
61
|
+
return pg;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function isPostgresUrlEnvKey(key) {
|
|
66
|
+
return (key === 'POSTGRES_URL' ||
|
|
67
|
+
key === 'PGURL' ||
|
|
68
|
+
key === 'PG_URL' ||
|
|
69
|
+
key === 'TLS_POSTGRES_DATABASE_URL');
|
|
70
|
+
}
|
|
71
|
+
function isMysqlUrlEnvKey(key) {
|
|
72
|
+
return (key === 'MYSQL_URL' ||
|
|
73
|
+
key === 'TLS_MYSQL_DATABASE_URL' ||
|
|
74
|
+
key === 'MARIADB_URL' ||
|
|
75
|
+
key === 'TLS_MARIADB_DATABASE_URL');
|
|
76
|
+
}
|
|
77
|
+
function ensureSslModeRequire(url) {
|
|
78
|
+
if (/[?&](sslmode|ssl|tls)=/i.test(url))
|
|
79
|
+
return url;
|
|
80
|
+
return url.includes('?') ? `${url}&sslmode=require` : `${url}?sslmode=require`;
|
|
81
|
+
}
|
|
82
|
+
function composePostgresUrlFromEnv(env) {
|
|
83
|
+
const host = env.PGHOST;
|
|
84
|
+
const database = env.PGDATABASE;
|
|
85
|
+
const user = env.PGUSERNAME || env.PGUSER || env.USER || env.USERNAME;
|
|
86
|
+
const password = env.PGPASSWORD;
|
|
87
|
+
const port = env.PGPORT;
|
|
88
|
+
const sslmode = env.PGSSLMODE;
|
|
89
|
+
if (!host && !database && !user && !password)
|
|
90
|
+
return undefined;
|
|
91
|
+
const auth = user != null && user !== ''
|
|
92
|
+
? password != null && password !== ''
|
|
93
|
+
? `${encodeURIComponent(user)}:${encodeURIComponent(password)}@`
|
|
94
|
+
: `${encodeURIComponent(user)}@`
|
|
95
|
+
: '';
|
|
96
|
+
const hostPart = host || 'localhost';
|
|
97
|
+
const portPart = port ? `:${port}` : '';
|
|
98
|
+
const dbPart = database ? `/${encodeURIComponent(database)}` : '';
|
|
99
|
+
const qs = sslmode ? `?sslmode=${encodeURIComponent(sslmode)}` : '';
|
|
100
|
+
return `postgres://${auth}${hostPart}${portPart}${dbPart}${qs}`;
|
|
101
|
+
}
|
|
102
|
+
function composeMysqlUrlFromEnv(env) {
|
|
103
|
+
const host = env.MYSQL_HOST || env.MARIADB_HOST;
|
|
104
|
+
const database = env.MYSQL_DATABASE || env.MARIADB_DATABASE;
|
|
105
|
+
const user = env.MYSQL_USER || env.MARIADB_USER;
|
|
106
|
+
const password = env.MYSQL_PASSWORD || env.MARIADB_PASSWORD;
|
|
107
|
+
const port = env.MYSQL_PORT || env.MARIADB_PORT;
|
|
108
|
+
if (!host && !database && !user && !password)
|
|
109
|
+
return undefined;
|
|
110
|
+
const auth = user != null && user !== ''
|
|
111
|
+
? password != null && password !== ''
|
|
112
|
+
? `${encodeURIComponent(user)}:${encodeURIComponent(password)}@`
|
|
113
|
+
: `${encodeURIComponent(user)}@`
|
|
114
|
+
: '';
|
|
115
|
+
const hostPart = host || 'localhost';
|
|
116
|
+
const portPart = port ? `:${port}` : '';
|
|
117
|
+
const dbPart = database ? `/${encodeURIComponent(database)}` : '';
|
|
118
|
+
return `mysql://${auth}${hostPart}${portPart}${dbPart}`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Detect adapter from a connection string protocol — Bun SQL–compatible.
|
|
122
|
+
*
|
|
123
|
+
* | Connection string | Adapter |
|
|
124
|
+
* | --- | --- |
|
|
125
|
+
* | `postgres://`, `postgresql://`, or host-style with no protocol | postgres |
|
|
126
|
+
* | `mysql://`, `mysql2://`, `mysqls://`, `mariadb://` | mysql |
|
|
127
|
+
* | `sqlite://`, `sqlite:`, `file://`, `file:`, `:memory:` | sqlite |
|
|
128
|
+
*
|
|
129
|
+
* Unknown protocols throw. Plain `*.db` / `*.sqlite` paths are treated as sqlite
|
|
130
|
+
* (Mesh convenience; Bun would require an explicit adapter for bare filenames).
|
|
131
|
+
*/
|
|
132
|
+
export function inferAdapterFromConnectionString(location) {
|
|
133
|
+
const trimmed = location.trim();
|
|
134
|
+
const lower = trimmed.toLowerCase();
|
|
135
|
+
if (lower === ':memory:' || lower.startsWith('sqlite:') || lower.startsWith('file:')) {
|
|
136
|
+
return 'sqlite';
|
|
137
|
+
}
|
|
138
|
+
if (lower.startsWith('mysql://') ||
|
|
139
|
+
lower.startsWith('mysql2://') ||
|
|
140
|
+
lower.startsWith('mysqls://') ||
|
|
141
|
+
lower.startsWith('mariadb://')) {
|
|
142
|
+
return 'mysql';
|
|
143
|
+
}
|
|
144
|
+
if (lower.startsWith('postgres://') || lower.startsWith('postgresql://')) {
|
|
145
|
+
return 'postgres';
|
|
146
|
+
}
|
|
147
|
+
// Explicit unknown scheme with :// (e.g. pg://, sqlite3://) — match Bun and throw.
|
|
148
|
+
// Do not treat `localhost:5432/db` or `user:pass@host/db` as schemes.
|
|
149
|
+
const schemeMatch = /^([a-z][a-z0-9+.-]*):\/\//i.exec(trimmed);
|
|
150
|
+
if (schemeMatch) {
|
|
151
|
+
const scheme = schemeMatch[1].toLowerCase();
|
|
152
|
+
throw new Error(`Unsupported SQL connection protocol "${scheme}:" in ${location}. Use postgres(ql)://, mysql(2|s)://, mariadb://, sqlite://, or file:.`);
|
|
153
|
+
}
|
|
154
|
+
// No protocol: Bun defaults to postgres for host-style strings.
|
|
155
|
+
// Mesh also accepts sqlite file paths (extension / relative path without host:port).
|
|
156
|
+
if (looksLikeSqliteFile(trimmed)) {
|
|
157
|
+
return 'sqlite';
|
|
158
|
+
}
|
|
159
|
+
return 'postgres';
|
|
160
|
+
}
|
|
161
|
+
function looksLikeSqliteFile(location) {
|
|
162
|
+
const lower = location.toLowerCase();
|
|
163
|
+
if (lower.endsWith('.db') ||
|
|
164
|
+
lower.endsWith('.sqlite') ||
|
|
165
|
+
lower.endsWith('.sqlite3') ||
|
|
166
|
+
lower === ':memory:') {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
// Relative/absolute path without a host:port authority
|
|
170
|
+
if (location.startsWith('./') || location.startsWith('../') || location.startsWith('/')) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
// Windows drive path
|
|
174
|
+
if (/^[a-zA-Z]:[\\/]/.test(location)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
export function parseSqlUri(location) {
|
|
180
|
+
const searchParams = {};
|
|
181
|
+
const adapter = inferAdapterFromConnectionString(location);
|
|
182
|
+
if (adapter === 'sqlite') {
|
|
183
|
+
let filePath = location.trim();
|
|
184
|
+
if (filePath.toLowerCase().startsWith('file:'))
|
|
185
|
+
filePath = filePath.slice('file:'.length);
|
|
186
|
+
else if (filePath.toLowerCase().startsWith('sqlite:')) {
|
|
187
|
+
filePath = filePath.slice('sqlite:'.length);
|
|
188
|
+
// sqlite://path vs sqlite:path
|
|
189
|
+
if (filePath.startsWith('//')) {
|
|
190
|
+
// sqlite:///abs → /abs ; sqlite://rel → keep //rel then strip one slash pair for URL form
|
|
191
|
+
if (filePath.startsWith('///')) {
|
|
192
|
+
filePath = filePath.slice(2); // ///abs → /abs
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
filePath = filePath.slice(2); // //rel.db → rel.db
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (filePath.startsWith('//') && !filePath.startsWith('///')) {
|
|
200
|
+
// file://absolute leftover
|
|
201
|
+
filePath = filePath.replace(/^\/\/+/, '/');
|
|
202
|
+
}
|
|
203
|
+
// Query string on sqlite URLs (mode=ro etc.) — strip for path, keep in searchParams
|
|
204
|
+
const qIdx = filePath.indexOf('?');
|
|
205
|
+
if (qIdx !== -1) {
|
|
206
|
+
const qs = new URLSearchParams(filePath.slice(qIdx + 1));
|
|
207
|
+
qs.forEach((value, key) => {
|
|
208
|
+
searchParams[key] = value;
|
|
209
|
+
});
|
|
210
|
+
filePath = filePath.slice(0, qIdx);
|
|
211
|
+
}
|
|
212
|
+
return { adapter: 'sqlite', filePath, searchParams };
|
|
213
|
+
}
|
|
214
|
+
// URL parser needs a known scheme; normalize aliases Bun also accepts.
|
|
215
|
+
let normalized = location.trim();
|
|
216
|
+
const wantsMysqlSsl = /^mysqls:/i.test(normalized);
|
|
217
|
+
normalized = normalized
|
|
218
|
+
.replace(/^mysqls:/i, 'mysql:')
|
|
219
|
+
.replace(/^mysql2:/i, 'mysql:')
|
|
220
|
+
.replace(/^mariadb:/i, 'mysql:');
|
|
221
|
+
// Host-style with no protocol → Bun treats as postgres
|
|
222
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(normalized) && adapter === 'postgres') {
|
|
223
|
+
normalized = `postgres://${normalized}`;
|
|
224
|
+
}
|
|
225
|
+
const url = new URL(normalized);
|
|
226
|
+
url.searchParams.forEach((value, key) => {
|
|
227
|
+
searchParams[key] = value;
|
|
228
|
+
});
|
|
229
|
+
const database = url.pathname.replace(/^\//, '') || undefined;
|
|
230
|
+
if (adapter === 'postgres') {
|
|
231
|
+
return {
|
|
232
|
+
adapter: 'postgres',
|
|
233
|
+
user: decode(url.username) || undefined,
|
|
234
|
+
password: decode(url.password) || undefined,
|
|
235
|
+
host: url.hostname || 'localhost',
|
|
236
|
+
port: url.port ? Number(url.port) : 5432,
|
|
237
|
+
database,
|
|
238
|
+
ssl: searchParams.ssl === 'true' || searchParams.sslmode === 'require',
|
|
239
|
+
searchParams,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
// mysql / mysql2 / mariadb / mysqls
|
|
243
|
+
return {
|
|
244
|
+
adapter: 'mysql',
|
|
245
|
+
user: decode(url.username) || undefined,
|
|
246
|
+
password: decode(url.password) || undefined,
|
|
247
|
+
host: url.hostname || 'localhost',
|
|
248
|
+
port: url.port ? Number(url.port) : 3306,
|
|
249
|
+
database,
|
|
250
|
+
ssl: wantsMysqlSsl || searchParams.ssl === 'true',
|
|
251
|
+
searchParams,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function decode(value) {
|
|
255
|
+
try {
|
|
256
|
+
return decodeURIComponent(value);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-mesh/transport-sql",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "^16.0.0 || ^17.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@apollo/subgraph": "^2.16.0",
|
|
10
|
+
"@dataplan/pg": "^1.2.1",
|
|
11
|
+
"@graphql-mesh/transport-common": "^1.1.2",
|
|
12
|
+
"@graphql-mesh/utils": "^0.107.3",
|
|
13
|
+
"@graphql-tools/utils": "^13.2.2",
|
|
14
|
+
"@whatwg-node/disposablestack": "^0.1.0",
|
|
15
|
+
"@whatwg-node/promise-helpers": "^2.0.1",
|
|
16
|
+
"dataloader": "^2.2.2",
|
|
17
|
+
"grafast": "^1.2.0",
|
|
18
|
+
"graphile-config": "^0.0.1-beta.14",
|
|
19
|
+
"mysql2": "^3.14.0",
|
|
20
|
+
"pg": "^8.23.1",
|
|
21
|
+
"pg-sql2": "^5.0.2",
|
|
22
|
+
"tslib": "^2.4.0"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "ardatan/graphql-mesh",
|
|
27
|
+
"directory": "packages/transports/sql"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.18.0"
|
|
32
|
+
},
|
|
33
|
+
"main": "cjs/index.js",
|
|
34
|
+
"module": "esm/index.js",
|
|
35
|
+
"typings": "typings/index.d.ts",
|
|
36
|
+
"typescript": {
|
|
37
|
+
"definition": "typings/index.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"type": "module",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./typings/index.d.cts",
|
|
44
|
+
"default": "./cjs/index.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./typings/index.d.ts",
|
|
48
|
+
"default": "./esm/index.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./typings/index.d.ts",
|
|
52
|
+
"default": "./esm/index.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqlAdapter } from './types.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Infer adapter from a transport `location` / connection URI.
|
|
4
|
+
* Prefer {@link inferAdapterFromConnectionString} for full Bun-compatible rules.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inferAdapterFromLocation(location: string | undefined): SqlAdapter | undefined;
|
|
7
|
+
export declare function quoteIdent(adapter: SqlAdapter, name: string): string;
|
|
8
|
+
export declare function placeholder(adapter: SqlAdapter, index: number): string;
|
|
9
|
+
export declare function resolveSqlitePath(location: string, cwd?: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqlAdapter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Infer adapter from a transport `location` / connection URI.
|
|
4
|
+
* Prefer {@link inferAdapterFromConnectionString} for full Bun-compatible rules.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inferAdapterFromLocation(location: string | undefined): SqlAdapter | undefined;
|
|
7
|
+
export declare function quoteIdent(adapter: SqlAdapter, name: string): string;
|
|
8
|
+
export declare function placeholder(adapter: SqlAdapter, index: number): string;
|
|
9
|
+
export declare function resolveSqlitePath(location: string, cwd?: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SqlPlanners } from './sql-builder.cjs';
|
|
2
|
+
import type { ParsedSqlMapping, SqlClient } from './types.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Detect a single equality column binder suitable for `WHERE col IN (...)` batching.
|
|
5
|
+
*/
|
|
6
|
+
export declare function batchableEqualityColumn(whereMapping: ParsedSqlMapping): string | undefined;
|
|
7
|
+
export declare function resolveEqualityKey(whereMapping: ParsedSqlMapping, column: string, graphqlArgs: Record<string, any>, parent: any): unknown;
|
|
8
|
+
export interface BatchSelectOpts {
|
|
9
|
+
client: SqlClient;
|
|
10
|
+
table: string;
|
|
11
|
+
kind: 'ROW' | 'ROWS';
|
|
12
|
+
selection: ParsedSqlMapping;
|
|
13
|
+
whereMapping: ParsedSqlMapping;
|
|
14
|
+
planners?: SqlPlanners;
|
|
15
|
+
column: string;
|
|
16
|
+
graphqlArgs?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Per-request DataLoader that batches ROW/ROWS lookups sharing the same table/column/args.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadBatchedByColumn(context: any, opts: BatchSelectOpts, key: unknown): Promise<any>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SqlPlanners } from './sql-builder.js';
|
|
2
|
+
import type { ParsedSqlMapping, SqlClient } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detect a single equality column binder suitable for `WHERE col IN (...)` batching.
|
|
5
|
+
*/
|
|
6
|
+
export declare function batchableEqualityColumn(whereMapping: ParsedSqlMapping): string | undefined;
|
|
7
|
+
export declare function resolveEqualityKey(whereMapping: ParsedSqlMapping, column: string, graphqlArgs: Record<string, any>, parent: any): unknown;
|
|
8
|
+
export interface BatchSelectOpts {
|
|
9
|
+
client: SqlClient;
|
|
10
|
+
table: string;
|
|
11
|
+
kind: 'ROW' | 'ROWS';
|
|
12
|
+
selection: ParsedSqlMapping;
|
|
13
|
+
whereMapping: ParsedSqlMapping;
|
|
14
|
+
planners?: SqlPlanners;
|
|
15
|
+
column: string;
|
|
16
|
+
graphqlArgs?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Per-request DataLoader that batches ROW/ROWS lookups sharing the same table/column/args.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadBatchedByColumn(context: any, opts: BatchSelectOpts, key: unknown): Promise<any>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SqlAdapter, SqlClient, SqlTransportOptions } from './types.cjs';
|
|
2
|
+
export interface CreateSqlClientOptions extends SqlTransportOptions {
|
|
3
|
+
adapter: SqlAdapter;
|
|
4
|
+
location: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** Force Node drivers even when `Bun.SQL` is present. */
|
|
7
|
+
preferNode?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function isBunSqlAvailable(): boolean;
|
|
10
|
+
export declare function createSqlClient(opts: CreateSqlClientOptions): SqlClient;
|
|
11
|
+
/**
|
|
12
|
+
* Wrap Bun's native `SQL` client when running under Bun.
|
|
13
|
+
* Uses `sql.unsafe(query, params)` so our adapter placeholders (`$1` / `?`) work as-is.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createBunSqlClient(opts: CreateSqlClientOptions): SqlClient;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap an existing `pg.Pool` (or compatible) as SqlClient.
|
|
18
|
+
*/
|
|
19
|
+
export declare function wrapPgPoolAsSqlClient(pool: {
|
|
20
|
+
query: (sql: string, params?: unknown[]) => Promise<{
|
|
21
|
+
rows: any[];
|
|
22
|
+
rowCount?: number | null;
|
|
23
|
+
}>;
|
|
24
|
+
end?: () => Promise<void>;
|
|
25
|
+
}): SqlClient;
|
|
26
|
+
/**
|
|
27
|
+
* Wrap an existing `mysql` / `mysql2` pool (legacy handler `pool` config) as SqlClient.
|
|
28
|
+
*/
|
|
29
|
+
export declare function wrapMysqlPoolAsSqlClient(pool: {
|
|
30
|
+
query: (...args: any[]) => any;
|
|
31
|
+
end?: (...args: any[]) => any;
|
|
32
|
+
promise?: () => {
|
|
33
|
+
query: (...args: any[]) => any;
|
|
34
|
+
end?: (...args: any[]) => any;
|
|
35
|
+
};
|
|
36
|
+
}): SqlClient;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SqlAdapter, SqlClient, SqlTransportOptions } from './types.js';
|
|
2
|
+
export interface CreateSqlClientOptions extends SqlTransportOptions {
|
|
3
|
+
adapter: SqlAdapter;
|
|
4
|
+
location: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** Force Node drivers even when `Bun.SQL` is present. */
|
|
7
|
+
preferNode?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function isBunSqlAvailable(): boolean;
|
|
10
|
+
export declare function createSqlClient(opts: CreateSqlClientOptions): SqlClient;
|
|
11
|
+
/**
|
|
12
|
+
* Wrap Bun's native `SQL` client when running under Bun.
|
|
13
|
+
* Uses `sql.unsafe(query, params)` so our adapter placeholders (`$1` / `?`) work as-is.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createBunSqlClient(opts: CreateSqlClientOptions): SqlClient;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap an existing `pg.Pool` (or compatible) as SqlClient.
|
|
18
|
+
*/
|
|
19
|
+
export declare function wrapPgPoolAsSqlClient(pool: {
|
|
20
|
+
query: (sql: string, params?: unknown[]) => Promise<{
|
|
21
|
+
rows: any[];
|
|
22
|
+
rowCount?: number | null;
|
|
23
|
+
}>;
|
|
24
|
+
end?: () => Promise<void>;
|
|
25
|
+
}): SqlClient;
|
|
26
|
+
/**
|
|
27
|
+
* Wrap an existing `mysql` / `mysql2` pool (legacy handler `pool` config) as SqlClient.
|
|
28
|
+
*/
|
|
29
|
+
export declare function wrapMysqlPoolAsSqlClient(pool: {
|
|
30
|
+
query: (...args: any[]) => any;
|
|
31
|
+
end?: (...args: any[]) => any;
|
|
32
|
+
promise?: () => {
|
|
33
|
+
query: (...args: any[]) => any;
|
|
34
|
+
end?: (...args: any[]) => any;
|
|
35
|
+
};
|
|
36
|
+
}): SqlClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqlDialect } from './types.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Infer dialect from a transport `location` / connection URI.
|
|
4
|
+
* Prefer {@link inferDialectFromConnectionString} for full Bun-compatible rules.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inferDialectFromLocation(location: string | undefined): SqlDialect | undefined;
|
|
7
|
+
export declare function quoteIdent(dialect: SqlDialect, name: string): string;
|
|
8
|
+
export declare function placeholder(dialect: SqlDialect, index: number): string;
|
|
9
|
+
export declare function resolveSqlitePath(location: string, cwd?: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqlDialect } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Infer dialect from a transport `location` / connection URI.
|
|
4
|
+
* Prefer {@link inferDialectFromConnectionString} for full Bun-compatible rules.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inferDialectFromLocation(location: string | undefined): SqlDialect | undefined;
|
|
7
|
+
export declare function quoteIdent(dialect: SqlDialect, name: string): string;
|
|
8
|
+
export declare function placeholder(dialect: SqlDialect, index: number): string;
|
|
9
|
+
export declare function resolveSqlitePath(location: string, cwd?: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type GraphQLNamedType, type GraphQLResolveInfo, type GraphQLSchema } from 'graphql';
|
|
2
|
+
type ResolveReferenceFn = (reference: any, context: any, info: GraphQLResolveInfo) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Record `__resolveReference` the way `@apollo/subgraph` expects
|
|
5
|
+
* (`extensions.apollo.subgraph.resolveReference`) so we can reuse
|
|
6
|
+
* `entitiesResolver` instead of maintaining our own `_entities` dispatch.
|
|
7
|
+
* Also mirror on `type.resolveReference` for Hive stub hydration helpers / tests.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setTypeResolveReference(type: GraphQLNamedType, resolveReference: ResolveReferenceFn): void;
|
|
10
|
+
export declare function getTypeResolveReference(type: GraphQLNamedType): ResolveReferenceFn | undefined;
|
|
11
|
+
/** Raw `@sql` plus composed `@join__directive(name: "sql")` payloads. */
|
|
12
|
+
export declare function getSqlDirectiveArgs(schema: GraphQLSchema, node: {
|
|
13
|
+
astNode?: unknown;
|
|
14
|
+
extensions?: unknown;
|
|
15
|
+
}): Record<string, unknown>[];
|
|
16
|
+
export type TypeLevelSqlExecutor = (sqlArgs: Record<string, unknown>, reference: any, context: any, info: GraphQLResolveInfo) => any;
|
|
17
|
+
/**
|
|
18
|
+
* Wire Federation entity resolution from type-level `@sql` (Connectors type-level pattern).
|
|
19
|
+
* Query `entity: true` is no longer used — presence of OBJECT `@sql` is the signal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function wireSqlEntityResolvers(schema: GraphQLSchema, opts: {
|
|
22
|
+
executeTypeLevelRow: TypeLevelSqlExecutor;
|
|
23
|
+
}): GraphQLSchema;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type GraphQLNamedType, type GraphQLResolveInfo, type GraphQLSchema } from 'graphql';
|
|
2
|
+
type ResolveReferenceFn = (reference: any, context: any, info: GraphQLResolveInfo) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Record `__resolveReference` the way `@apollo/subgraph` expects
|
|
5
|
+
* (`extensions.apollo.subgraph.resolveReference`) so we can reuse
|
|
6
|
+
* `entitiesResolver` instead of maintaining our own `_entities` dispatch.
|
|
7
|
+
* Also mirror on `type.resolveReference` for Hive stub hydration helpers / tests.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setTypeResolveReference(type: GraphQLNamedType, resolveReference: ResolveReferenceFn): void;
|
|
10
|
+
export declare function getTypeResolveReference(type: GraphQLNamedType): ResolveReferenceFn | undefined;
|
|
11
|
+
/** Raw `@sql` plus composed `@join__directive(name: "sql")` payloads. */
|
|
12
|
+
export declare function getSqlDirectiveArgs(schema: GraphQLSchema, node: {
|
|
13
|
+
astNode?: unknown;
|
|
14
|
+
extensions?: unknown;
|
|
15
|
+
}): Record<string, unknown>[];
|
|
16
|
+
export type TypeLevelSqlExecutor = (sqlArgs: Record<string, unknown>, reference: any, context: any, info: GraphQLResolveInfo) => any;
|
|
17
|
+
/**
|
|
18
|
+
* Wire Federation entity resolution from type-level `@sql` (Connectors type-level pattern).
|
|
19
|
+
* Query `entity: true` is no longer used — presence of OBJECT `@sql` is the signal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function wireSqlEntityResolvers(schema: GraphQLSchema, opts: {
|
|
22
|
+
executeTypeLevelRow: TypeLevelSqlExecutor;
|
|
23
|
+
}): GraphQLSchema;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { type DisposableExecutor } from '@graphql-mesh/transport-common';
|
|
3
|
+
import type { SqlClient } from './types.cjs';
|
|
4
|
+
export interface GetSqlExecutorOpts {
|
|
5
|
+
subgraph: GraphQLSchema;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
client?: SqlClient;
|
|
8
|
+
}
|
|
9
|
+
export declare function getSqlExecutor({ subgraph, cwd, client, }: GetSqlExecutorOpts): Promise<DisposableExecutor>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { type DisposableExecutor } from '@graphql-mesh/transport-common';
|
|
3
|
+
import type { SqlClient } from './types.js';
|
|
4
|
+
export interface GetSqlExecutorOpts {
|
|
5
|
+
subgraph: GraphQLSchema;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
client?: SqlClient;
|
|
8
|
+
}
|
|
9
|
+
export declare function getSqlExecutor({ subgraph, cwd, client, }: GetSqlExecutorOpts): Promise<DisposableExecutor>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SqlTransportOptions } from './types.cjs';
|
|
2
|
+
export * from './adapter.cjs';
|
|
3
|
+
export * from './batch.cjs';
|
|
4
|
+
export * from './client.cjs';
|
|
5
|
+
export * from './entity.cjs';
|
|
6
|
+
export * from './execution.cjs';
|
|
7
|
+
export * from './mapping.cjs';
|
|
8
|
+
export * from './plan.cjs';
|
|
9
|
+
export * from './sql-builder.cjs';
|
|
10
|
+
export * from './uri.cjs';
|
|
11
|
+
export type * from './types.cjs';
|
|
12
|
+
declare const _default: {
|
|
13
|
+
getSubgraphExecutor({ subgraph, cwd }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<SqlTransportOptions>): Promise<import("@graphql-mesh/transport-common").DisposableExecutor>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|