@drizzle-graphql-suite/schema 0.7.0 → 0.8.1
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/index.js +24 -12
- package/package.json +1 -1
- package/schema-builder.d.ts +17 -13
package/index.js
CHANGED
|
@@ -1191,16 +1191,22 @@ class SchemaBuilder {
|
|
|
1191
1191
|
delete operators.OR;
|
|
1192
1192
|
const entries = Object.entries(operators);
|
|
1193
1193
|
if (operators.OR) {
|
|
1194
|
-
|
|
1195
|
-
throw new GraphQLError2(`WHERE ${columnName}: Cannot specify both fields and 'OR' in column operators!`);
|
|
1196
|
-
}
|
|
1197
|
-
const variants2 = [];
|
|
1194
|
+
const orVariants = [];
|
|
1198
1195
|
for (const variant of operators.OR) {
|
|
1199
1196
|
const extracted = this.extractColumnFilters(column, columnName, variant);
|
|
1200
1197
|
if (extracted)
|
|
1201
|
-
|
|
1198
|
+
orVariants.push(extracted);
|
|
1202
1199
|
}
|
|
1203
|
-
|
|
1200
|
+
const orClause = orVariants.length > 1 ? or(...orVariants) : orVariants.length === 1 ? orVariants[0] : undefined;
|
|
1201
|
+
if (entries.length <= 1)
|
|
1202
|
+
return orClause;
|
|
1203
|
+
const { OR: _, ...rest } = operators;
|
|
1204
|
+
const fieldClause = this.extractColumnFilters(column, columnName, rest);
|
|
1205
|
+
if (!fieldClause)
|
|
1206
|
+
return orClause;
|
|
1207
|
+
if (!orClause)
|
|
1208
|
+
return fieldClause;
|
|
1209
|
+
return and(fieldClause, orClause);
|
|
1204
1210
|
}
|
|
1205
1211
|
const comparisonOps = { eq, ne, gt, gte, lt, lte };
|
|
1206
1212
|
const stringOps = { like, notLike, ilike, notIlike };
|
|
@@ -1258,16 +1264,22 @@ class SchemaBuilder {
|
|
|
1258
1264
|
}
|
|
1259
1265
|
}
|
|
1260
1266
|
if (filters.OR) {
|
|
1261
|
-
|
|
1262
|
-
throw new GraphQLError2(`WHERE ${tableName}: Cannot specify both fields and 'OR' in table filters!`);
|
|
1263
|
-
}
|
|
1264
|
-
const variants2 = [];
|
|
1267
|
+
const orVariants = [];
|
|
1265
1268
|
for (const variant of filters.OR) {
|
|
1266
1269
|
const extracted = this.extractAllFilters(table, tableName, variant);
|
|
1267
1270
|
if (extracted)
|
|
1268
|
-
|
|
1271
|
+
orVariants.push(extracted);
|
|
1269
1272
|
}
|
|
1270
|
-
|
|
1273
|
+
const orClause = orVariants.length > 1 ? or(...orVariants) : orVariants.length === 1 ? orVariants[0] : undefined;
|
|
1274
|
+
if (columnEntries.length === 0 && relationEntries.length === 0)
|
|
1275
|
+
return orClause;
|
|
1276
|
+
const { OR: _, ...rest } = filters;
|
|
1277
|
+
const fieldClause = this.extractAllFilters(table, tableName, rest);
|
|
1278
|
+
if (!fieldClause)
|
|
1279
|
+
return orClause;
|
|
1280
|
+
if (!orClause)
|
|
1281
|
+
return fieldClause;
|
|
1282
|
+
return and(fieldClause, orClause);
|
|
1271
1283
|
}
|
|
1272
1284
|
const variants = [];
|
|
1273
1285
|
for (const [columnName, operators] of columnEntries) {
|
package/package.json
CHANGED
package/schema-builder.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Column, Relation, Table, TablesRelationalConfig } from 'drizzle-orm';
|
|
2
|
+
import { type SQL } from 'drizzle-orm';
|
|
3
|
+
import { type PgDatabase, PgTable } from 'drizzle-orm/pg-core';
|
|
2
4
|
import { GraphQLSchema } from 'graphql';
|
|
5
|
+
import type { ResolveTree } from 'graphql-parse-resolve-info';
|
|
6
|
+
import { type TableNamedRelations } from './data-mappers';
|
|
3
7
|
import type { BuildSchemaConfig, GeneratedEntities, PermissionConfig } from './types';
|
|
4
8
|
export declare class SchemaBuilder {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
protected db: PgDatabase<any, any, any>;
|
|
10
|
+
protected tables: Record<string, PgTable>;
|
|
11
|
+
protected relationMap: Record<string, Record<string, TableNamedRelations>>;
|
|
12
|
+
protected relationalSchema: TablesRelationalConfig;
|
|
13
|
+
protected tableNamesMap: Record<string, string>;
|
|
10
14
|
private config;
|
|
11
15
|
private hooks;
|
|
12
16
|
private adapter;
|
|
@@ -50,15 +54,15 @@ export declare class SchemaBuilder {
|
|
|
50
54
|
private createInsertSingleResolver;
|
|
51
55
|
private createUpdateResolver;
|
|
52
56
|
private createDeleteResolver;
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
protected extractColumnFilters(column: Column, columnName: string, operators: any): SQL | undefined;
|
|
58
|
+
protected extractTableColumnFilters(table: Table, tableName: string, filters: any): SQL | undefined;
|
|
55
59
|
/** Combined filter extraction: column filters + relation filters */
|
|
56
60
|
private extractAllFilters;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
protected extractRelationFilters(table: Table, tableName: string, relationName: string, filterValue: any): SQL | undefined;
|
|
62
|
+
protected buildExistsSubquery(parentTable: Table, targetTable: Table, relation: Relation, targetTableName: string, filterValue: any, quantifier: 'some' | 'every' | 'none'): SQL | undefined;
|
|
63
|
+
protected buildJoinCondition(parentTable: Table, _targetTable: Table, relation: Relation): SQL | undefined;
|
|
64
|
+
protected extractOrderBy(table: Table, orderArgs: any): SQL[];
|
|
65
|
+
protected extractColumns(tree: Record<string, ResolveTree>, table: Table): Record<string, true>;
|
|
62
66
|
private extractColumnsSQLFormat;
|
|
63
67
|
private getFieldsByTypeName;
|
|
64
68
|
private extractRelationsParams;
|