@vantreeseba/drizzle-graphql 7.5.0 → 7.6.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/README.md +90 -0
- package/dist/README.md +90 -0
- package/dist/index.cjs +562 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -2
- package/dist/index.d.ts +104 -2
- package/dist/index.js +563 -188
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
One as One2,
|
|
39
39
|
or,
|
|
40
40
|
relationsFilterToSQL,
|
|
41
|
+
SQL,
|
|
41
42
|
sql as sql2
|
|
42
43
|
} from "drizzle-orm";
|
|
43
44
|
import {
|
|
@@ -1154,7 +1155,7 @@ var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCon
|
|
|
1154
1155
|
}
|
|
1155
1156
|
return rows;
|
|
1156
1157
|
};
|
|
1157
|
-
var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
1158
|
+
var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits, scopes) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
1158
1159
|
const parentTable = tables[tableName];
|
|
1159
1160
|
const targetTableName = relEntry.targetTableName;
|
|
1160
1161
|
const targetTable = tables[targetTableName];
|
|
@@ -1215,10 +1216,16 @@ var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits
|
|
|
1215
1216
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
1216
1217
|
const executor = resolveExecutor(db, context);
|
|
1217
1218
|
const uniqueIds = [...new Set(parentIds)];
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1219
|
+
const scope = resolveScope(scopes, context, filterCtx);
|
|
1220
|
+
let whereCondition = withScope(
|
|
1221
|
+
scope,
|
|
1222
|
+
targetTableName,
|
|
1223
|
+
targetTable,
|
|
1224
|
+
and(
|
|
1225
|
+
inArray(foreignCol, uniqueIds),
|
|
1226
|
+
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0,
|
|
1227
|
+
cursorValues ? buildCursorCondition(targetTable, cursorEntries, cursorValues, nullOrdering) : void 0
|
|
1228
|
+
)
|
|
1222
1229
|
);
|
|
1223
1230
|
if (distinct) {
|
|
1224
1231
|
const keys = await selectDistinctKeys({
|
|
@@ -2124,9 +2131,11 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
2124
2131
|
const table = tables[tableName];
|
|
2125
2132
|
const columns = visibleColumns(table);
|
|
2126
2133
|
const columnEntries = Object.entries(columns);
|
|
2134
|
+
const contextColumns = cacheCtx.contextValuesOf?.(tableName);
|
|
2135
|
+
const writableEntries = contextColumns ? columnEntries.filter(([columnName]) => !(columnName in contextColumns)) : columnEntries;
|
|
2127
2136
|
const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
|
|
2128
2137
|
const insertFields = Object.fromEntries(
|
|
2129
|
-
|
|
2138
|
+
writableEntries.map(([columnName, column]) => {
|
|
2130
2139
|
const converted = drizzleColumnToGraphQLType(
|
|
2131
2140
|
column,
|
|
2132
2141
|
columnName,
|
|
@@ -2142,7 +2151,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
2142
2151
|
})
|
|
2143
2152
|
);
|
|
2144
2153
|
const updateFields = Object.fromEntries(
|
|
2145
|
-
|
|
2154
|
+
writableEntries.map(([columnName, column]) => {
|
|
2146
2155
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
2147
2156
|
const operations = cacheCtx.featureOf(tableName).fieldUpdateOperations ? fieldUpdateInputType(column, columnName, tableName) : void 0;
|
|
2148
2157
|
const field = operations ? { ...converted, type: operations } : converted;
|
|
@@ -2665,7 +2674,69 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2665
2674
|
}
|
|
2666
2675
|
return variants.length ? variants.length > 1 ? and(...variants) : variants[0] : void 0;
|
|
2667
2676
|
};
|
|
2668
|
-
var
|
|
2677
|
+
var resolveScope = (scopes, context, filterCtx) => {
|
|
2678
|
+
if (!scopes) {
|
|
2679
|
+
return void 0;
|
|
2680
|
+
}
|
|
2681
|
+
return {
|
|
2682
|
+
has: (tableName) => !!scopes(tableName),
|
|
2683
|
+
on: (tableName, table) => {
|
|
2684
|
+
const hook = scopes(tableName);
|
|
2685
|
+
if (!hook) {
|
|
2686
|
+
return void 0;
|
|
2687
|
+
}
|
|
2688
|
+
const predicate = hook(context, table);
|
|
2689
|
+
if (predicate === void 0 || predicate === null) {
|
|
2690
|
+
return void 0;
|
|
2691
|
+
}
|
|
2692
|
+
if (is3(predicate, SQL)) {
|
|
2693
|
+
return predicate;
|
|
2694
|
+
}
|
|
2695
|
+
if (typeof predicate !== "object") {
|
|
2696
|
+
throw new GraphQLError4(
|
|
2697
|
+
`Drizzle-GraphQL Error: the scope for '${tableName}' returned a ${typeof predicate}. A scope returns a filter object, a Drizzle SQL expression, or undefined.`
|
|
2698
|
+
);
|
|
2699
|
+
}
|
|
2700
|
+
return extractFilters(table, tableName, predicate, relationFilterCtx(filterCtx, tableName));
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
};
|
|
2704
|
+
var withScope = (scope, tableName, table, condition) => {
|
|
2705
|
+
const predicate = scope?.on(tableName, table);
|
|
2706
|
+
return predicate ? and(condition, predicate) : condition;
|
|
2707
|
+
};
|
|
2708
|
+
var bindPolicies = (policies, filterCtx) => policies?.scope || policies?.contextValues ? {
|
|
2709
|
+
scope: policies.scope ? (context) => resolveScope(policies.scope, context, filterCtx) : void 0,
|
|
2710
|
+
contextValues: policies.contextValues
|
|
2711
|
+
} : void 0;
|
|
2712
|
+
var applyContextValues = (values, hooks, context) => {
|
|
2713
|
+
if (!hooks) {
|
|
2714
|
+
return values;
|
|
2715
|
+
}
|
|
2716
|
+
for (const [columnName, hook] of Object.entries(hooks)) {
|
|
2717
|
+
values[columnName] = hook(context);
|
|
2718
|
+
}
|
|
2719
|
+
return values;
|
|
2720
|
+
};
|
|
2721
|
+
var applyContextValuesAll = (rows, hooks, context) => {
|
|
2722
|
+
if (!hooks) {
|
|
2723
|
+
return rows;
|
|
2724
|
+
}
|
|
2725
|
+
for (const row of rows) {
|
|
2726
|
+
applyContextValues(row, hooks, context);
|
|
2727
|
+
}
|
|
2728
|
+
return rows;
|
|
2729
|
+
};
|
|
2730
|
+
var stripContextValues = (values, hooks) => {
|
|
2731
|
+
if (!hooks) {
|
|
2732
|
+
return values;
|
|
2733
|
+
}
|
|
2734
|
+
for (const columnName of Object.keys(hooks)) {
|
|
2735
|
+
delete values[columnName];
|
|
2736
|
+
}
|
|
2737
|
+
return values;
|
|
2738
|
+
};
|
|
2739
|
+
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx, limits, scope) => {
|
|
2669
2740
|
const relationsForTable = relationMap[tableName];
|
|
2670
2741
|
if (!relationsForTable) {
|
|
2671
2742
|
return void 0;
|
|
@@ -2711,8 +2782,13 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2711
2782
|
const offset = relationArgs?.offset ?? void 0;
|
|
2712
2783
|
const limit = is3(relEntry.relation, One2) ? relationArgs?.limit ?? void 0 : applyLimitPolicy(relationArgs?.limit, limits?.(targetTableName), `${tableName}.${relName}`);
|
|
2713
2784
|
const relWhere = relationArgs?.where;
|
|
2714
|
-
thisRecord.where = relWhere ? {
|
|
2715
|
-
RAW: (aliasedTable2) =>
|
|
2785
|
+
thisRecord.where = relWhere || scope?.has(targetTableName) ? {
|
|
2786
|
+
RAW: (aliasedTable2) => withScope(
|
|
2787
|
+
scope,
|
|
2788
|
+
targetTableName,
|
|
2789
|
+
aliasedTable2,
|
|
2790
|
+
relWhere ? extractFilters(aliasedTable2, relName, relWhere, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
2791
|
+
)
|
|
2716
2792
|
} : void 0;
|
|
2717
2793
|
const hasPagination = offset != null || limit != null;
|
|
2718
2794
|
const pkNames = targetPkNames ?? [];
|
|
@@ -2728,14 +2804,15 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2728
2804
|
typeNameMapper,
|
|
2729
2805
|
false,
|
|
2730
2806
|
filterCtx,
|
|
2731
|
-
limits
|
|
2807
|
+
limits,
|
|
2808
|
+
scope
|
|
2732
2809
|
) : void 0;
|
|
2733
2810
|
thisRecord.with = relWith;
|
|
2734
2811
|
args[relName] = thisRecord;
|
|
2735
2812
|
}
|
|
2736
2813
|
return args;
|
|
2737
2814
|
};
|
|
2738
|
-
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx, limits) => {
|
|
2815
|
+
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx, limits, scope) => {
|
|
2739
2816
|
if (!info) {
|
|
2740
2817
|
return void 0;
|
|
2741
2818
|
}
|
|
@@ -2748,7 +2825,8 @@ var extractRelationsParams = (relationMap, tables, tableName, info, typeName, ty
|
|
|
2748
2825
|
typeNameMapper,
|
|
2749
2826
|
true,
|
|
2750
2827
|
filterCtx,
|
|
2751
|
-
limits
|
|
2828
|
+
limits,
|
|
2829
|
+
scope
|
|
2752
2830
|
);
|
|
2753
2831
|
};
|
|
2754
2832
|
var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
@@ -3158,7 +3236,8 @@ var prepareMutationRelationColumns = (params) => {
|
|
|
3158
3236
|
typeName,
|
|
3159
3237
|
typeNameMapper,
|
|
3160
3238
|
void 0,
|
|
3161
|
-
params.limits
|
|
3239
|
+
params.limits,
|
|
3240
|
+
params.scope
|
|
3162
3241
|
) : void 0;
|
|
3163
3242
|
const hasRelations = !!(withParams && Object.keys(withParams).length);
|
|
3164
3243
|
const baseColumns = extractSelectedColumnsFromTreeSQLFormat(parsedInfo.fieldsByTypeName[typeName], table, {
|
|
@@ -3392,7 +3471,8 @@ var runRelationalSelect = async (opts) => {
|
|
|
3392
3471
|
single,
|
|
3393
3472
|
filterCtx,
|
|
3394
3473
|
pkNames,
|
|
3395
|
-
after
|
|
3474
|
+
after,
|
|
3475
|
+
scope
|
|
3396
3476
|
} = opts;
|
|
3397
3477
|
const distinct = opts.distinct?.length ? opts.distinct : void 0;
|
|
3398
3478
|
const cursorSelected = !single && isCursorFieldSelected(parsedInfo.fieldsByTypeName[typeName], table);
|
|
@@ -3424,7 +3504,12 @@ var runRelationalSelect = async (opts) => {
|
|
|
3424
3504
|
tableName,
|
|
3425
3505
|
distinct,
|
|
3426
3506
|
pkNames: pkNames ?? [],
|
|
3427
|
-
where:
|
|
3507
|
+
where: withScope(
|
|
3508
|
+
scope,
|
|
3509
|
+
tableName,
|
|
3510
|
+
table,
|
|
3511
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
3512
|
+
),
|
|
3428
3513
|
orderBy,
|
|
3429
3514
|
limit: single ? 1 : opts.limit,
|
|
3430
3515
|
offset
|
|
@@ -3451,15 +3536,23 @@ var runRelationalSelect = async (opts) => {
|
|
|
3451
3536
|
// exactly the ordering the cursor encodes and the keyset predicate compares against.
|
|
3452
3537
|
(aliasedTable2) => cursorOrderExprs(aliasedTable2, cursorEntries)
|
|
3453
3538
|
) : orderBy ? (aliasedTable2) => extractOrderBy(aliasedTable2, orderBy, relationFilterCtx(filterCtx, tableName), where) : needsDefaultOrder && pkNames?.length ? (aliasedTable2) => primaryKeyOrderExprs(aliasedTable2, pkNames) : void 0,
|
|
3454
|
-
where: distinctKeys ?
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3539
|
+
where: distinctKeys ? (
|
|
3540
|
+
// The distinct pass already ran inside the scope, so the keys it picked are in it.
|
|
3541
|
+
{ RAW: (aliasedTable2) => primaryKeyRestriction(aliasedTable2, pkNames, distinctKeys) }
|
|
3542
|
+
) : where || cursorValues || scope?.has(tableName) ? {
|
|
3543
|
+
RAW: (aliasedTable2) => withScope(
|
|
3544
|
+
scope,
|
|
3545
|
+
tableName,
|
|
3546
|
+
aliasedTable2,
|
|
3547
|
+
and(
|
|
3548
|
+
where ? extractFilters(aliasedTable2, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0,
|
|
3549
|
+
cursorValues ? buildCursorCondition(
|
|
3550
|
+
aliasedTable2,
|
|
3551
|
+
cursorEntries,
|
|
3552
|
+
cursorValues,
|
|
3553
|
+
opts.nullOrdering ?? "nulls-smallest"
|
|
3554
|
+
) : void 0
|
|
3555
|
+
)
|
|
3463
3556
|
)
|
|
3464
3557
|
} : void 0,
|
|
3465
3558
|
with: relationMap[tableName] ? extractRelationsParams(
|
|
@@ -3470,7 +3563,8 @@ var runRelationalSelect = async (opts) => {
|
|
|
3470
3563
|
typeName,
|
|
3471
3564
|
typeNameMapper,
|
|
3472
3565
|
filterCtx,
|
|
3473
|
-
opts.limits
|
|
3566
|
+
opts.limits,
|
|
3567
|
+
scope
|
|
3474
3568
|
) : void 0
|
|
3475
3569
|
};
|
|
3476
3570
|
if (single) {
|
|
@@ -3807,7 +3901,7 @@ var assembleAggregateRow = (row, request, target) => {
|
|
|
3807
3901
|
}
|
|
3808
3902
|
return result;
|
|
3809
3903
|
};
|
|
3810
|
-
var generateAggregate = (db, tableName, table, typeName, fieldName, filterArgs, filterCtx) => {
|
|
3904
|
+
var generateAggregate = (db, tableName, table, typeName, fieldName, filterArgs, filterCtx, scopes) => {
|
|
3811
3905
|
const target = aggregateTarget(table, tableName, typeName);
|
|
3812
3906
|
const queryArgs = {
|
|
3813
3907
|
where: { type: filterArgs }
|
|
@@ -3821,8 +3915,14 @@ var generateAggregate = (db, tableName, table, typeName, fieldName, filterArgs,
|
|
|
3821
3915
|
return {};
|
|
3822
3916
|
}
|
|
3823
3917
|
let query = resolveExecutor(db, context).select(request.selection).from(table);
|
|
3824
|
-
|
|
3825
|
-
|
|
3918
|
+
const where = withScope(
|
|
3919
|
+
resolveScope(scopes, context, filterCtx),
|
|
3920
|
+
tableName,
|
|
3921
|
+
table,
|
|
3922
|
+
args.where ? extractFilters(table, tableName, args.where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
3923
|
+
);
|
|
3924
|
+
if (where) {
|
|
3925
|
+
query = query.where(where);
|
|
3826
3926
|
}
|
|
3827
3927
|
const rows = await query;
|
|
3828
3928
|
return assembleAggregateRow(rows[0] ?? {}, request, target);
|
|
@@ -3834,7 +3934,7 @@ var generateAggregate = (db, tableName, table, typeName, fieldName, filterArgs,
|
|
|
3834
3934
|
};
|
|
3835
3935
|
};
|
|
3836
3936
|
var GROUP_KEY = "__dgql_group_key";
|
|
3837
|
-
var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filterCtx) => {
|
|
3937
|
+
var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filterCtx, scopes) => {
|
|
3838
3938
|
return ({ tableName, relationName, relEntry }) => {
|
|
3839
3939
|
const parentTable = tables[tableName];
|
|
3840
3940
|
const targetTableName = relEntry.targetTableName;
|
|
@@ -3869,9 +3969,14 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
|
|
|
3869
3969
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
3870
3970
|
const executor = resolveExecutor(db, context);
|
|
3871
3971
|
const uniqueIds = [...new Set(parentIds)];
|
|
3872
|
-
const whereCondition =
|
|
3873
|
-
|
|
3874
|
-
|
|
3972
|
+
const whereCondition = withScope(
|
|
3973
|
+
resolveScope(scopes, context, filterCtx),
|
|
3974
|
+
targetTableName,
|
|
3975
|
+
targetTable,
|
|
3976
|
+
and2(
|
|
3977
|
+
inArray2(foreignCol, uniqueIds),
|
|
3978
|
+
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
3979
|
+
)
|
|
3875
3980
|
);
|
|
3876
3981
|
const rows = await executor.select({ [GROUP_KEY]: foreignCol, ...request.selection }).from(targetTable).where(whereCondition).groupBy(foreignCol);
|
|
3877
3982
|
const byKey = new Map(rows.map((row) => [row[GROUP_KEY], row]));
|
|
@@ -4004,7 +4109,7 @@ var buildHavingCondition = (having, columns) => {
|
|
|
4004
4109
|
}
|
|
4005
4110
|
return conditions.length ? and2(...conditions) : void 0;
|
|
4006
4111
|
};
|
|
4007
|
-
var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx) => {
|
|
4112
|
+
var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx, scopes) => {
|
|
4008
4113
|
const target = aggregateTarget(table, tableName, typeName);
|
|
4009
4114
|
const groupable = groupableColumns(table, tableName);
|
|
4010
4115
|
const columns = getColumns3(table);
|
|
@@ -4038,8 +4143,14 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
4038
4143
|
...request.selection
|
|
4039
4144
|
};
|
|
4040
4145
|
let query = resolveExecutor(db, context).select(selection).from(table);
|
|
4041
|
-
|
|
4042
|
-
|
|
4146
|
+
const where = withScope(
|
|
4147
|
+
resolveScope(scopes, context, filterCtx),
|
|
4148
|
+
tableName,
|
|
4149
|
+
table,
|
|
4150
|
+
args.where ? extractFilters(table, tableName, args.where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
4151
|
+
);
|
|
4152
|
+
if (where) {
|
|
4153
|
+
query = query.where(where);
|
|
4043
4154
|
}
|
|
4044
4155
|
query = query.groupBy(...keyColumns.map(([, column]) => column));
|
|
4045
4156
|
const havingCondition = buildHavingCondition(args.having, columns);
|
|
@@ -4065,7 +4176,7 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
4065
4176
|
};
|
|
4066
4177
|
|
|
4067
4178
|
// src/util/builders/mysql.ts
|
|
4068
|
-
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
4179
|
+
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits, policies) => {
|
|
4069
4180
|
const queryBase = db.query[tableName];
|
|
4070
4181
|
if (!queryBase) {
|
|
4071
4182
|
throw new Error(
|
|
@@ -4100,6 +4211,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
4100
4211
|
single: false,
|
|
4101
4212
|
filterCtx,
|
|
4102
4213
|
limits,
|
|
4214
|
+
scope: policies?.scope?.(context),
|
|
4103
4215
|
pkNames,
|
|
4104
4216
|
db: executor,
|
|
4105
4217
|
// MySQL sorts NULLs as the smallest values (first in ASC).
|
|
@@ -4112,7 +4224,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
4112
4224
|
args: queryArgs
|
|
4113
4225
|
};
|
|
4114
4226
|
};
|
|
4115
|
-
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
4227
|
+
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits, policies) => {
|
|
4116
4228
|
const queryBase = db.query[tableName];
|
|
4117
4229
|
if (!queryBase) {
|
|
4118
4230
|
throw new Error(
|
|
@@ -4141,6 +4253,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4141
4253
|
single: true,
|
|
4142
4254
|
filterCtx,
|
|
4143
4255
|
limits,
|
|
4256
|
+
scope: policies?.scope?.(context),
|
|
4144
4257
|
pkNames,
|
|
4145
4258
|
db: executor
|
|
4146
4259
|
});
|
|
@@ -4151,7 +4264,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4151
4264
|
args: queryArgs
|
|
4152
4265
|
};
|
|
4153
4266
|
};
|
|
4154
|
-
var generateInsertArray = (db,
|
|
4267
|
+
var generateInsertArray = (db, tableName, table, baseType, fieldName, txCtx, policies) => {
|
|
4155
4268
|
const queryArgs = {
|
|
4156
4269
|
values: {
|
|
4157
4270
|
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
@@ -4162,7 +4275,11 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
4162
4275
|
resolver: async (_source, args, context, info) => {
|
|
4163
4276
|
try {
|
|
4164
4277
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4165
|
-
const input =
|
|
4278
|
+
const input = applyContextValuesAll(
|
|
4279
|
+
remapFromGraphQLArrayInput(args.values, table),
|
|
4280
|
+
policies?.contextValues?.(tableName),
|
|
4281
|
+
context
|
|
4282
|
+
);
|
|
4166
4283
|
if (!input.length) {
|
|
4167
4284
|
throw new GraphQLError6("No values were provided!");
|
|
4168
4285
|
}
|
|
@@ -4176,7 +4293,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
4176
4293
|
args: queryArgs
|
|
4177
4294
|
};
|
|
4178
4295
|
};
|
|
4179
|
-
var generateInsertSingle = (db,
|
|
4296
|
+
var generateInsertSingle = (db, tableName, table, baseType, fieldName, txCtx, policies) => {
|
|
4180
4297
|
const queryArgs = {
|
|
4181
4298
|
values: {
|
|
4182
4299
|
type: new GraphQLNonNull5(baseType)
|
|
@@ -4187,7 +4304,11 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
|
|
|
4187
4304
|
resolver: async (_source, args, context, info) => {
|
|
4188
4305
|
try {
|
|
4189
4306
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4190
|
-
const input =
|
|
4307
|
+
const input = applyContextValues(
|
|
4308
|
+
remapFromGraphQLSingleInput(args.values, table),
|
|
4309
|
+
policies?.contextValues?.(tableName),
|
|
4310
|
+
context
|
|
4311
|
+
);
|
|
4191
4312
|
await executor.insert(table).values(input);
|
|
4192
4313
|
return { isSuccess: true };
|
|
4193
4314
|
});
|
|
@@ -4198,7 +4319,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
|
|
|
4198
4319
|
args: queryArgs
|
|
4199
4320
|
};
|
|
4200
4321
|
};
|
|
4201
|
-
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
4322
|
+
var generateUpsert = (db, tableName, table, baseType, onConflictType, fieldName, single, txCtx, policies) => {
|
|
4202
4323
|
const queryArgs = {
|
|
4203
4324
|
values: {
|
|
4204
4325
|
type: single ? new GraphQLNonNull5(baseType) : new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
@@ -4214,7 +4335,11 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
4214
4335
|
resolver: async (_source, args, context, info) => {
|
|
4215
4336
|
try {
|
|
4216
4337
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4217
|
-
const input =
|
|
4338
|
+
const input = applyContextValuesAll(
|
|
4339
|
+
single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table),
|
|
4340
|
+
policies?.contextValues?.(tableName),
|
|
4341
|
+
context
|
|
4342
|
+
);
|
|
4218
4343
|
if (!input.length) {
|
|
4219
4344
|
throw new GraphQLError6("No values were provided!");
|
|
4220
4345
|
}
|
|
@@ -4241,7 +4366,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
4241
4366
|
args: queryArgs
|
|
4242
4367
|
};
|
|
4243
4368
|
};
|
|
4244
|
-
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
4369
|
+
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx, policies) => {
|
|
4245
4370
|
const queryArgs = {
|
|
4246
4371
|
set: {
|
|
4247
4372
|
type: new GraphQLNonNull5(setArgs)
|
|
@@ -4256,12 +4381,21 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
4256
4381
|
try {
|
|
4257
4382
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4258
4383
|
const { where, set } = args;
|
|
4259
|
-
const
|
|
4384
|
+
const scope = policies?.scope?.(context);
|
|
4385
|
+
const input = stripContextValues(
|
|
4386
|
+
remapUpdateInput(set, table, tableName),
|
|
4387
|
+
policies?.contextValues?.(tableName)
|
|
4388
|
+
);
|
|
4260
4389
|
if (!Object.keys(input).length) {
|
|
4261
4390
|
throw new GraphQLError6("Unable to update with no values specified!");
|
|
4262
4391
|
}
|
|
4263
4392
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4264
|
-
const filters =
|
|
4393
|
+
const filters = withScope(
|
|
4394
|
+
scope,
|
|
4395
|
+
tableName,
|
|
4396
|
+
table,
|
|
4397
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
4398
|
+
);
|
|
4265
4399
|
if (single) {
|
|
4266
4400
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4267
4401
|
}
|
|
@@ -4279,7 +4413,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
4279
4413
|
args: queryArgs
|
|
4280
4414
|
};
|
|
4281
4415
|
};
|
|
4282
|
-
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
4416
|
+
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx, policies) => {
|
|
4283
4417
|
const queryArgs = {
|
|
4284
4418
|
updates: {
|
|
4285
4419
|
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(updateManyInput)))
|
|
@@ -4294,14 +4428,21 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
4294
4428
|
if (!updates.length) {
|
|
4295
4429
|
throw new GraphQLError6("No updates were provided!");
|
|
4296
4430
|
}
|
|
4431
|
+
const scope = policies?.scope?.(context);
|
|
4432
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
4297
4433
|
const entries = updates.map(({ where, set }) => {
|
|
4298
|
-
const input = remapUpdateInput(set, table, tableName);
|
|
4434
|
+
const input = stripContextValues(remapUpdateInput(set, table, tableName), contextColumns);
|
|
4299
4435
|
if (!Object.keys(input).length) {
|
|
4300
4436
|
throw new GraphQLError6("Unable to update with no values specified!");
|
|
4301
4437
|
}
|
|
4302
4438
|
return {
|
|
4303
4439
|
set: input,
|
|
4304
|
-
filters:
|
|
4440
|
+
filters: withScope(
|
|
4441
|
+
scope,
|
|
4442
|
+
tableName,
|
|
4443
|
+
table,
|
|
4444
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
4445
|
+
)
|
|
4305
4446
|
};
|
|
4306
4447
|
});
|
|
4307
4448
|
await executor.transaction(async (tx) => {
|
|
@@ -4322,7 +4463,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
4322
4463
|
args: queryArgs
|
|
4323
4464
|
};
|
|
4324
4465
|
};
|
|
4325
|
-
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
4466
|
+
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx, policies) => {
|
|
4326
4467
|
const queryArgs = {
|
|
4327
4468
|
where: {
|
|
4328
4469
|
type: single || requireWhere ? new GraphQLNonNull5(filterArgs) : filterArgs
|
|
@@ -4334,8 +4475,14 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
|
|
|
4334
4475
|
try {
|
|
4335
4476
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4336
4477
|
const { where } = args;
|
|
4478
|
+
const scope = policies?.scope?.(context);
|
|
4337
4479
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4338
|
-
const filters =
|
|
4480
|
+
const filters = withScope(
|
|
4481
|
+
scope,
|
|
4482
|
+
tableName,
|
|
4483
|
+
table,
|
|
4484
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
4485
|
+
);
|
|
4339
4486
|
if (single) {
|
|
4340
4487
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4341
4488
|
}
|
|
@@ -4383,12 +4530,16 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4383
4530
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
4384
4531
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
4385
4532
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
4533
|
+
const scopes = options.policies?.scope;
|
|
4534
|
+
const contextValuesOf = options.policies?.contextValues;
|
|
4535
|
+
const policies = bindPolicies(options.policies, filterCtx);
|
|
4386
4536
|
const resolverFactory = createRelationResolverFactory(
|
|
4387
4537
|
db,
|
|
4388
4538
|
tables,
|
|
4389
4539
|
"nulls-smallest",
|
|
4390
4540
|
filterCtx,
|
|
4391
|
-
limits
|
|
4541
|
+
limits,
|
|
4542
|
+
scopes
|
|
4392
4543
|
);
|
|
4393
4544
|
const cacheCtx = {
|
|
4394
4545
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -4406,9 +4557,10 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4406
4557
|
limits,
|
|
4407
4558
|
docs: options.docs ?? {},
|
|
4408
4559
|
primaryKeyOf: (name) => tables[name] ? mysqlPrimaryKeyPropNames(tables[name]) : [],
|
|
4560
|
+
contextValuesOf,
|
|
4409
4561
|
featureOf
|
|
4410
4562
|
};
|
|
4411
|
-
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4563
|
+
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx, scopes) : void 0;
|
|
4412
4564
|
const queries = {};
|
|
4413
4565
|
const mutations = {};
|
|
4414
4566
|
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
@@ -4478,7 +4630,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4478
4630
|
typeNameMapper,
|
|
4479
4631
|
filterCtx,
|
|
4480
4632
|
tableFeatures.distinct,
|
|
4481
|
-
limits
|
|
4633
|
+
limits,
|
|
4634
|
+
policies
|
|
4482
4635
|
);
|
|
4483
4636
|
const selectSingleGenerated = generateSelectSingle(
|
|
4484
4637
|
db,
|
|
@@ -4491,7 +4644,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4491
4644
|
typeName,
|
|
4492
4645
|
typeNameMapper,
|
|
4493
4646
|
filterCtx,
|
|
4494
|
-
limits
|
|
4647
|
+
limits,
|
|
4648
|
+
policies
|
|
4495
4649
|
);
|
|
4496
4650
|
const insertArrGenerated = tableFeatures.insert ? generateInsertArray(
|
|
4497
4651
|
db,
|
|
@@ -4499,7 +4653,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4499
4653
|
schema[tableName],
|
|
4500
4654
|
insertInput,
|
|
4501
4655
|
createArrayFieldName,
|
|
4502
|
-
mutationTxCtx
|
|
4656
|
+
mutationTxCtx,
|
|
4657
|
+
policies
|
|
4503
4658
|
) : void 0;
|
|
4504
4659
|
const insertSingleGenerated = tableFeatures.insert ? generateInsertSingle(
|
|
4505
4660
|
db,
|
|
@@ -4507,7 +4662,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4507
4662
|
schema[tableName],
|
|
4508
4663
|
insertInput,
|
|
4509
4664
|
createSingleFieldName,
|
|
4510
|
-
mutationTxCtx
|
|
4665
|
+
mutationTxCtx,
|
|
4666
|
+
policies
|
|
4511
4667
|
) : void 0;
|
|
4512
4668
|
const onConflictInput = tableFeatures.upsert ? generateOnConflictInput({
|
|
4513
4669
|
table: schema[tableName],
|
|
@@ -4518,21 +4674,25 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4518
4674
|
}) : void 0;
|
|
4519
4675
|
const upsertArrGenerated = onConflictInput ? generateUpsert(
|
|
4520
4676
|
db,
|
|
4677
|
+
tableName,
|
|
4521
4678
|
schema[tableName],
|
|
4522
4679
|
insertInput,
|
|
4523
4680
|
onConflictInput,
|
|
4524
4681
|
upsertArrayFieldName,
|
|
4525
4682
|
false,
|
|
4526
|
-
mutationTxCtx
|
|
4683
|
+
mutationTxCtx,
|
|
4684
|
+
policies
|
|
4527
4685
|
) : void 0;
|
|
4528
4686
|
const upsertSingleGenerated = onConflictInput ? generateUpsert(
|
|
4529
4687
|
db,
|
|
4688
|
+
tableName,
|
|
4530
4689
|
schema[tableName],
|
|
4531
4690
|
insertInput,
|
|
4532
4691
|
onConflictInput,
|
|
4533
4692
|
upsertSingleFieldName,
|
|
4534
4693
|
true,
|
|
4535
|
-
mutationTxCtx
|
|
4694
|
+
mutationTxCtx,
|
|
4695
|
+
policies
|
|
4536
4696
|
) : void 0;
|
|
4537
4697
|
const updateGenerated = tableFeatures.update ? generateUpdate(
|
|
4538
4698
|
db,
|
|
@@ -4544,7 +4704,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4544
4704
|
false,
|
|
4545
4705
|
tableFeatures.requireWhere,
|
|
4546
4706
|
filterCtx,
|
|
4547
|
-
mutationTxCtx
|
|
4707
|
+
mutationTxCtx,
|
|
4708
|
+
policies
|
|
4548
4709
|
) : void 0;
|
|
4549
4710
|
const updateSingleGenerated = tableFeatures.update ? generateUpdate(
|
|
4550
4711
|
db,
|
|
@@ -4556,7 +4717,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4556
4717
|
true,
|
|
4557
4718
|
tableFeatures.requireWhere,
|
|
4558
4719
|
filterCtx,
|
|
4559
|
-
mutationTxCtx
|
|
4720
|
+
mutationTxCtx,
|
|
4721
|
+
policies
|
|
4560
4722
|
) : void 0;
|
|
4561
4723
|
const updateManyInput = tableFeatures.update && tableFeatures.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
4562
4724
|
const updateManyGenerated = updateManyInput ? generateUpdateMany(
|
|
@@ -4566,7 +4728,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4566
4728
|
updateManyInput,
|
|
4567
4729
|
updateManyFieldName,
|
|
4568
4730
|
filterCtx,
|
|
4569
|
-
mutationTxCtx
|
|
4731
|
+
mutationTxCtx,
|
|
4732
|
+
policies
|
|
4570
4733
|
) : void 0;
|
|
4571
4734
|
const deleteGenerated = tableFeatures.delete ? generateDelete(
|
|
4572
4735
|
db,
|
|
@@ -4577,7 +4740,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4577
4740
|
false,
|
|
4578
4741
|
tableFeatures.requireWhere,
|
|
4579
4742
|
filterCtx,
|
|
4580
|
-
mutationTxCtx
|
|
4743
|
+
mutationTxCtx,
|
|
4744
|
+
policies
|
|
4581
4745
|
) : void 0;
|
|
4582
4746
|
const deleteSingleGenerated = tableFeatures.delete ? generateDelete(
|
|
4583
4747
|
db,
|
|
@@ -4588,7 +4752,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4588
4752
|
true,
|
|
4589
4753
|
tableFeatures.requireWhere,
|
|
4590
4754
|
filterCtx,
|
|
4591
|
-
mutationTxCtx
|
|
4755
|
+
mutationTxCtx,
|
|
4756
|
+
policies
|
|
4592
4757
|
) : void 0;
|
|
4593
4758
|
const updateCountGenerated = tableFeatures.update && tableFeatures.countMutations ? generateWriteCount({
|
|
4594
4759
|
db,
|
|
@@ -4621,7 +4786,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4621
4786
|
typeName,
|
|
4622
4787
|
aggregateFieldName,
|
|
4623
4788
|
tableFilters,
|
|
4624
|
-
filterCtx
|
|
4789
|
+
filterCtx,
|
|
4790
|
+
scopes
|
|
4625
4791
|
) : void 0;
|
|
4626
4792
|
const groupByType = tableFeatures.aggregates && tableFeatures.groupBy ? generateGroupByType(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
4627
4793
|
const groupByEnum = groupByType ? generateGroupByEnum(schema[tableName], tableName, typeName) : void 0;
|
|
@@ -4635,7 +4801,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
4635
4801
|
tableFilters,
|
|
4636
4802
|
groupByEnum,
|
|
4637
4803
|
havingInput,
|
|
4638
|
-
filterCtx
|
|
4804
|
+
filterCtx,
|
|
4805
|
+
scopes
|
|
4639
4806
|
) : void 0;
|
|
4640
4807
|
queries[selectArrGenerated.name] = {
|
|
4641
4808
|
type: selectArrOutput,
|
|
@@ -4874,8 +5041,9 @@ var createNestedWriteTypes = (params) => {
|
|
|
4874
5041
|
return cached;
|
|
4875
5042
|
}
|
|
4876
5043
|
const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
|
|
5044
|
+
const contextColumns = cacheCtx.contextValuesOf?.(plan.targetTableName);
|
|
4877
5045
|
const fields = Object.fromEntries(
|
|
4878
|
-
Object.entries(visibleColumns(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
|
|
5046
|
+
Object.entries(visibleColumns(plan.targetTable)).filter(([columnName]) => columnName !== omitted && !contextColumns?.[columnName]).map(([columnName, column]) => [
|
|
4879
5047
|
columnName,
|
|
4880
5048
|
drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
|
|
4881
5049
|
])
|
|
@@ -4974,8 +5142,8 @@ var createNestedWriteTypes = (params) => {
|
|
|
4974
5142
|
var mergedOps = (entries) => Object.assign({}, ...entries.map((entry) => entry.ops));
|
|
4975
5143
|
var asArray = (value) => Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
4976
5144
|
var createNestedWriteRuntime = (params) => {
|
|
4977
|
-
const { plans, filterCtx } = params;
|
|
4978
|
-
const conditionOf = (plan, filter, operation) => {
|
|
5145
|
+
const { plans, filterCtx, scopes, contextValues } = params;
|
|
5146
|
+
const conditionOf = (plan, filter, operation, scope) => {
|
|
4979
5147
|
const condition = extractFilters(
|
|
4980
5148
|
plan.targetTable,
|
|
4981
5149
|
plan.targetTableName,
|
|
@@ -4987,7 +5155,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4987
5155
|
`Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
|
|
4988
5156
|
);
|
|
4989
5157
|
}
|
|
4990
|
-
return condition;
|
|
5158
|
+
return withScope(scope, plan.targetTableName, plan.targetTable, condition);
|
|
4991
5159
|
};
|
|
4992
5160
|
const assertSingleOperation = (plan, op) => {
|
|
4993
5161
|
const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
|
|
@@ -4997,7 +5165,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4997
5165
|
);
|
|
4998
5166
|
}
|
|
4999
5167
|
};
|
|
5000
|
-
const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where(eq3(plan.foreignCol, key));
|
|
5168
|
+
const detachAll = async (executor, plan, key, scope) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where(withScope(scope, plan.targetTableName, plan.targetTable, eq3(plan.foreignCol, key)));
|
|
5001
5169
|
return {
|
|
5002
5170
|
enabled: (tableName) => !!plans[tableName],
|
|
5003
5171
|
split: (tableName, values) => {
|
|
@@ -5031,12 +5199,13 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5031
5199
|
}
|
|
5032
5200
|
return columns;
|
|
5033
5201
|
},
|
|
5034
|
-
applyParentSide: async (executor, tableName, ops) => {
|
|
5202
|
+
applyParentSide: async (executor, tableName, ops, context) => {
|
|
5035
5203
|
const tablePlans = plans[tableName];
|
|
5036
5204
|
const patch = {};
|
|
5037
5205
|
if (!tablePlans) {
|
|
5038
5206
|
return patch;
|
|
5039
5207
|
}
|
|
5208
|
+
const scope = resolveScope(scopes, context, filterCtx);
|
|
5040
5209
|
for (const [relationName, op] of Object.entries(ops)) {
|
|
5041
5210
|
const plan = tablePlans[relationName];
|
|
5042
5211
|
if (!plan || plan.fkSide !== "parent") {
|
|
@@ -5044,7 +5213,11 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5044
5213
|
}
|
|
5045
5214
|
assertSingleOperation(plan, op);
|
|
5046
5215
|
if (op["create"] !== void 0) {
|
|
5047
|
-
const values =
|
|
5216
|
+
const values = applyContextValues(
|
|
5217
|
+
remapFromGraphQLSingleInput({ ...op["create"] }, plan.targetTable),
|
|
5218
|
+
contextValues?.(plan.targetTableName),
|
|
5219
|
+
context
|
|
5220
|
+
);
|
|
5048
5221
|
const inserted = await executor.insert(plan.targetTable).values(values).returning();
|
|
5049
5222
|
const created = inserted[0];
|
|
5050
5223
|
if (!created) {
|
|
@@ -5054,7 +5227,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5054
5227
|
}
|
|
5055
5228
|
patch[plan.localColPropName] = created[plan.foreignColPropName];
|
|
5056
5229
|
} else if (op["connect"] !== void 0) {
|
|
5057
|
-
const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
|
|
5230
|
+
const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect", scope));
|
|
5058
5231
|
if (rows.length !== 1) {
|
|
5059
5232
|
throw new GraphQLError7(
|
|
5060
5233
|
`Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
|
|
@@ -5067,11 +5240,12 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5067
5240
|
}
|
|
5068
5241
|
return patch;
|
|
5069
5242
|
},
|
|
5070
|
-
applyChildSide: async (executor, tableName, ops, parentRows) => {
|
|
5243
|
+
applyChildSide: async (executor, tableName, ops, parentRows, context) => {
|
|
5071
5244
|
const tablePlans = plans[tableName];
|
|
5072
5245
|
if (!tablePlans) {
|
|
5073
5246
|
return;
|
|
5074
5247
|
}
|
|
5248
|
+
const scope = resolveScope(scopes, context, filterCtx);
|
|
5075
5249
|
for (const [relationName, op] of Object.entries(ops)) {
|
|
5076
5250
|
const plan = tablePlans[relationName];
|
|
5077
5251
|
if (!plan || plan.fkSide !== "child") {
|
|
@@ -5088,34 +5262,38 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5088
5262
|
);
|
|
5089
5263
|
}
|
|
5090
5264
|
if (op["set"] !== void 0) {
|
|
5091
|
-
await detachAll(executor, plan, key);
|
|
5265
|
+
await detachAll(executor, plan, key, scope);
|
|
5092
5266
|
for (const filter of asArray(op["set"])) {
|
|
5093
|
-
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "set"));
|
|
5267
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "set", scope));
|
|
5094
5268
|
}
|
|
5095
5269
|
}
|
|
5096
5270
|
if (op["disconnect"] !== void 0) {
|
|
5097
5271
|
if (plan.isOne) {
|
|
5098
5272
|
if (op["disconnect"] === true) {
|
|
5099
|
-
await detachAll(executor, plan, key);
|
|
5273
|
+
await detachAll(executor, plan, key, scope);
|
|
5100
5274
|
}
|
|
5101
5275
|
} else {
|
|
5102
5276
|
for (const filter of asArray(op["disconnect"])) {
|
|
5103
|
-
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where(and3(eq3(plan.foreignCol, key), conditionOf(plan, filter, "disconnect")));
|
|
5277
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where(and3(eq3(plan.foreignCol, key), conditionOf(plan, filter, "disconnect", scope)));
|
|
5104
5278
|
}
|
|
5105
5279
|
}
|
|
5106
5280
|
}
|
|
5107
5281
|
const attaches = op["connect"] !== void 0 || op["create"] !== void 0;
|
|
5108
5282
|
if (plan.isOne && attaches && plan.canDetach && op["set"] === void 0) {
|
|
5109
|
-
await detachAll(executor, plan, key);
|
|
5283
|
+
await detachAll(executor, plan, key, scope);
|
|
5110
5284
|
}
|
|
5111
5285
|
if (op["connect"] !== void 0) {
|
|
5112
5286
|
for (const filter of asArray(op["connect"])) {
|
|
5113
|
-
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "connect"));
|
|
5287
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "connect", scope));
|
|
5114
5288
|
}
|
|
5115
5289
|
}
|
|
5116
5290
|
if (op["create"] !== void 0) {
|
|
5117
5291
|
const rows = asArray(op["create"]).map((row) => ({
|
|
5118
|
-
...
|
|
5292
|
+
...applyContextValues(
|
|
5293
|
+
remapFromGraphQLSingleInput({ ...row }, plan.targetTable),
|
|
5294
|
+
contextValues?.(plan.targetTableName),
|
|
5295
|
+
context
|
|
5296
|
+
),
|
|
5119
5297
|
[plan.foreignColPropName]: key
|
|
5120
5298
|
}));
|
|
5121
5299
|
if (rows.length) {
|
|
@@ -5128,30 +5306,30 @@ var createNestedWriteRuntime = (params) => {
|
|
|
5128
5306
|
};
|
|
5129
5307
|
};
|
|
5130
5308
|
var writeWithNestedOps = async (params) => {
|
|
5131
|
-
const { executor, runtime, tableName, entries, remapValues, write } = params;
|
|
5309
|
+
const { executor, runtime, tableName, entries, remapValues, write, context } = params;
|
|
5132
5310
|
return executor.transaction(async (tx) => {
|
|
5133
5311
|
const rows = [];
|
|
5134
5312
|
for (const entry of entries) {
|
|
5135
|
-
const patch = await runtime.applyParentSide(tx, tableName, entry.ops);
|
|
5313
|
+
const patch = await runtime.applyParentSide(tx, tableName, entry.ops, context);
|
|
5136
5314
|
const written = await write(tx, { ...remapValues(entry.columns), ...patch });
|
|
5137
|
-
await runtime.applyChildSide(tx, tableName, entry.ops, written);
|
|
5315
|
+
await runtime.applyChildSide(tx, tableName, entry.ops, written, context);
|
|
5138
5316
|
rows.push(...written);
|
|
5139
5317
|
}
|
|
5140
5318
|
return rows;
|
|
5141
5319
|
});
|
|
5142
5320
|
};
|
|
5143
5321
|
var updateWithNestedOps = async (params) => {
|
|
5144
|
-
const { executor, runtime, tableName, columns, ops, remapValues, write } = params;
|
|
5322
|
+
const { executor, runtime, tableName, columns, ops, remapValues, write, context } = params;
|
|
5145
5323
|
return executor.transaction(async (tx) => {
|
|
5146
|
-
const patch = await runtime.applyParentSide(tx, tableName, ops);
|
|
5324
|
+
const patch = await runtime.applyParentSide(tx, tableName, ops, context);
|
|
5147
5325
|
const rows = await write(tx, { ...remapValues(columns), ...patch });
|
|
5148
|
-
await runtime.applyChildSide(tx, tableName, ops, rows);
|
|
5326
|
+
await runtime.applyChildSide(tx, tableName, ops, rows, context);
|
|
5149
5327
|
return rows;
|
|
5150
5328
|
});
|
|
5151
5329
|
};
|
|
5152
5330
|
|
|
5153
5331
|
// src/util/builders/pg.ts
|
|
5154
|
-
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
5332
|
+
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits, policies) => {
|
|
5155
5333
|
const queryBase = db.query[tableName];
|
|
5156
5334
|
const table = tables[tableName];
|
|
5157
5335
|
const limitPolicy = limits?.(tableName);
|
|
@@ -5167,6 +5345,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5167
5345
|
try {
|
|
5168
5346
|
const parsedInfo = parseResolveInfo3(info, { deep: true });
|
|
5169
5347
|
const { executor, queryBase: requestQueryBase } = resolveQueryExecutor(db, context, tableName, queryBase);
|
|
5348
|
+
const scope = policies?.scope?.(context);
|
|
5170
5349
|
const limit = applyLimitPolicy(args.limit, limitPolicy, fieldName);
|
|
5171
5350
|
if (requestQueryBase) {
|
|
5172
5351
|
return await runRelationalSelect({
|
|
@@ -5185,6 +5364,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5185
5364
|
limits,
|
|
5186
5365
|
pkNames,
|
|
5187
5366
|
db: executor,
|
|
5367
|
+
scope,
|
|
5188
5368
|
// PostgreSQL sorts NULLs as the largest values (last in ASC).
|
|
5189
5369
|
nullOrdering: "nulls-largest"
|
|
5190
5370
|
});
|
|
@@ -5223,7 +5403,12 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5223
5403
|
}
|
|
5224
5404
|
}
|
|
5225
5405
|
const cursorCondition = after != null && cursorEntries ? buildCursorCondition(table, cursorEntries, decodeCursor(after, cursorEntries), "nulls-largest") : void 0;
|
|
5226
|
-
const baseWhereSql =
|
|
5406
|
+
const baseWhereSql = withScope(
|
|
5407
|
+
scope,
|
|
5408
|
+
tableName,
|
|
5409
|
+
table,
|
|
5410
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5411
|
+
);
|
|
5227
5412
|
const whereSql = cursorCondition ? and4(baseWhereSql, cursorCondition) : baseWhereSql;
|
|
5228
5413
|
let distinctKeys;
|
|
5229
5414
|
if (distinct?.length) {
|
|
@@ -5278,7 +5463,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5278
5463
|
args: queryArgs
|
|
5279
5464
|
};
|
|
5280
5465
|
};
|
|
5281
|
-
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
5466
|
+
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits, policies) => {
|
|
5282
5467
|
const queryBase = db.query[tableName];
|
|
5283
5468
|
const queryArgs = selectSingleArgs(orderArgs, filterArgs);
|
|
5284
5469
|
const table = tables[tableName];
|
|
@@ -5289,6 +5474,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5289
5474
|
try {
|
|
5290
5475
|
const parsedInfo = parseResolveInfo3(info, { deep: true });
|
|
5291
5476
|
const { executor, queryBase: requestQueryBase } = resolveQueryExecutor(db, context, tableName, queryBase);
|
|
5477
|
+
const scope = policies?.scope?.(context);
|
|
5292
5478
|
if (requestQueryBase) {
|
|
5293
5479
|
return await runRelationalSelect({
|
|
5294
5480
|
queryBase: requestQueryBase,
|
|
@@ -5304,7 +5490,8 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5304
5490
|
filterCtx,
|
|
5305
5491
|
limits,
|
|
5306
5492
|
pkNames,
|
|
5307
|
-
db: executor
|
|
5493
|
+
db: executor,
|
|
5494
|
+
scope
|
|
5308
5495
|
});
|
|
5309
5496
|
}
|
|
5310
5497
|
const { offset, orderBy, where } = args;
|
|
@@ -5314,8 +5501,14 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5314
5501
|
{ tableName, relationMap, tables }
|
|
5315
5502
|
);
|
|
5316
5503
|
let q = executor.select(selectedColumnsSql).from(table);
|
|
5317
|
-
|
|
5318
|
-
|
|
5504
|
+
const whereSql = withScope(
|
|
5505
|
+
scope,
|
|
5506
|
+
tableName,
|
|
5507
|
+
table,
|
|
5508
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5509
|
+
);
|
|
5510
|
+
if (whereSql) {
|
|
5511
|
+
q = q.where(whereSql);
|
|
5319
5512
|
}
|
|
5320
5513
|
if (orderBy) {
|
|
5321
5514
|
q = q.orderBy(...extractOrderBy(table, orderBy, relationFilterCtx(filterCtx, tableName), where));
|
|
@@ -5336,7 +5529,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5336
5529
|
};
|
|
5337
5530
|
};
|
|
5338
5531
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig2);
|
|
5339
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5532
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies) => {
|
|
5340
5533
|
const queryArgs = {
|
|
5341
5534
|
values: {
|
|
5342
5535
|
type: new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(baseType)))
|
|
@@ -5353,7 +5546,13 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5353
5546
|
}
|
|
5354
5547
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
5355
5548
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
5356
|
-
const
|
|
5549
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
5550
|
+
const scope = policies?.scope?.(context);
|
|
5551
|
+
const input = nestedEntries ? [] : applyContextValuesAll(
|
|
5552
|
+
remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table),
|
|
5553
|
+
contextColumns,
|
|
5554
|
+
context
|
|
5555
|
+
);
|
|
5357
5556
|
const parsedInfo = parseResolveInfo3(info, {
|
|
5358
5557
|
deep: true
|
|
5359
5558
|
});
|
|
@@ -5366,7 +5565,8 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5366
5565
|
table,
|
|
5367
5566
|
pkNames,
|
|
5368
5567
|
parsedInfo,
|
|
5369
|
-
limits
|
|
5568
|
+
limits,
|
|
5569
|
+
scope
|
|
5370
5570
|
});
|
|
5371
5571
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5372
5572
|
const runInsert = async (target, values) => {
|
|
@@ -5381,8 +5581,9 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5381
5581
|
runtime: nested,
|
|
5382
5582
|
tableName,
|
|
5383
5583
|
entries: nestedEntries,
|
|
5384
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5385
|
-
write: (tx, values) => runInsert(tx, [values])
|
|
5584
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
5585
|
+
write: (tx, values) => runInsert(tx, [values]),
|
|
5586
|
+
context
|
|
5386
5587
|
}) : await runInsert(executor, input);
|
|
5387
5588
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
5388
5589
|
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
@@ -5394,7 +5595,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5394
5595
|
args: queryArgs
|
|
5395
5596
|
};
|
|
5396
5597
|
};
|
|
5397
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5598
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies) => {
|
|
5398
5599
|
const queryArgs = {
|
|
5399
5600
|
values: {
|
|
5400
5601
|
type: new GraphQLNonNull7(baseType)
|
|
@@ -5408,7 +5609,13 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5408
5609
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5409
5610
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
|
|
5410
5611
|
const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
|
|
5411
|
-
const
|
|
5612
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
5613
|
+
const scope = policies?.scope?.(context);
|
|
5614
|
+
const input = nestedEntry ? {} : applyContextValues(
|
|
5615
|
+
remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table),
|
|
5616
|
+
contextColumns,
|
|
5617
|
+
context
|
|
5618
|
+
);
|
|
5412
5619
|
const parsedInfo = parseResolveInfo3(info, {
|
|
5413
5620
|
deep: true
|
|
5414
5621
|
});
|
|
@@ -5421,7 +5628,8 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5421
5628
|
table,
|
|
5422
5629
|
pkNames,
|
|
5423
5630
|
parsedInfo,
|
|
5424
|
-
limits
|
|
5631
|
+
limits,
|
|
5632
|
+
scope
|
|
5425
5633
|
});
|
|
5426
5634
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
5427
5635
|
const runInsert = async (target, values) => {
|
|
@@ -5436,8 +5644,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5436
5644
|
runtime: nested,
|
|
5437
5645
|
tableName,
|
|
5438
5646
|
entries: [nestedEntry],
|
|
5439
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5440
|
-
write: runInsert
|
|
5647
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
5648
|
+
write: runInsert,
|
|
5649
|
+
context
|
|
5441
5650
|
}) : await runInsert(executor, input);
|
|
5442
5651
|
if (!result[0]) {
|
|
5443
5652
|
if (!conflictDoNothing) {
|
|
@@ -5455,7 +5664,7 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5455
5664
|
args: queryArgs
|
|
5456
5665
|
};
|
|
5457
5666
|
};
|
|
5458
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5667
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
5459
5668
|
const queryArgs = {
|
|
5460
5669
|
values: {
|
|
5461
5670
|
type: single ? new GraphQLNonNull7(baseType) : new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(baseType)))
|
|
@@ -5477,7 +5686,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5477
5686
|
}
|
|
5478
5687
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
5479
5688
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
5480
|
-
const
|
|
5689
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
5690
|
+
const scope = policies?.scope?.(context);
|
|
5691
|
+
const input = nestedEntries ? [] : applyContextValuesAll(
|
|
5692
|
+
remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table),
|
|
5693
|
+
contextColumns,
|
|
5694
|
+
context
|
|
5695
|
+
);
|
|
5481
5696
|
const parsedInfo = parseResolveInfo3(info, { deep: true });
|
|
5482
5697
|
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
5483
5698
|
relationMap,
|
|
@@ -5488,7 +5703,8 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5488
5703
|
table,
|
|
5489
5704
|
pkNames,
|
|
5490
5705
|
parsedInfo,
|
|
5491
|
-
limits
|
|
5706
|
+
limits,
|
|
5707
|
+
scope
|
|
5492
5708
|
});
|
|
5493
5709
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5494
5710
|
const runUpsert = async (target, values) => {
|
|
@@ -5503,7 +5719,8 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5503
5719
|
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
5504
5720
|
});
|
|
5505
5721
|
let query = target.insert(table).values(values).returning(returning);
|
|
5506
|
-
|
|
5722
|
+
const setWhere = withScope(scope, tableName, table, plan.setWhere);
|
|
5723
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere });
|
|
5507
5724
|
return await query;
|
|
5508
5725
|
};
|
|
5509
5726
|
const result = nestedEntries ? await writeWithNestedOps({
|
|
@@ -5511,8 +5728,9 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5511
5728
|
runtime: nested,
|
|
5512
5729
|
tableName,
|
|
5513
5730
|
entries: nestedEntries,
|
|
5514
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5515
|
-
write: (tx, values) => runUpsert(tx, [values])
|
|
5731
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
5732
|
+
write: (tx, values) => runUpsert(tx, [values]),
|
|
5733
|
+
context
|
|
5516
5734
|
}) : await runUpsert(executor, input);
|
|
5517
5735
|
if (single && !result[0]) {
|
|
5518
5736
|
return void 0;
|
|
@@ -5527,7 +5745,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5527
5745
|
args: queryArgs
|
|
5528
5746
|
};
|
|
5529
5747
|
};
|
|
5530
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5748
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
5531
5749
|
const queryArgs = {
|
|
5532
5750
|
set: {
|
|
5533
5751
|
type: new GraphQLNonNull7(setArgs)
|
|
@@ -5543,6 +5761,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5543
5761
|
try {
|
|
5544
5762
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5545
5763
|
const { where, set } = args;
|
|
5764
|
+
const scope = policies?.scope?.(context);
|
|
5546
5765
|
const parsedInfo = parseResolveInfo3(info, {
|
|
5547
5766
|
deep: true
|
|
5548
5767
|
});
|
|
@@ -5555,16 +5774,25 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5555
5774
|
table,
|
|
5556
5775
|
pkNames,
|
|
5557
5776
|
parsedInfo,
|
|
5558
|
-
limits
|
|
5777
|
+
limits,
|
|
5778
|
+
scope
|
|
5559
5779
|
});
|
|
5560
5780
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5561
5781
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
5562
|
-
const input =
|
|
5782
|
+
const input = stripContextValues(
|
|
5783
|
+
remapUpdateInput(entry ? entry.columns : set, table, tableName),
|
|
5784
|
+
policies?.contextValues?.(tableName)
|
|
5785
|
+
);
|
|
5563
5786
|
if (!Object.keys(input).length && !nestedOps) {
|
|
5564
5787
|
throw new GraphQLError8("Unable to update with no values specified!");
|
|
5565
5788
|
}
|
|
5566
5789
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5567
|
-
const filters =
|
|
5790
|
+
const filters = withScope(
|
|
5791
|
+
scope,
|
|
5792
|
+
tableName,
|
|
5793
|
+
table,
|
|
5794
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
5795
|
+
);
|
|
5568
5796
|
if (single) {
|
|
5569
5797
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5570
5798
|
}
|
|
@@ -5584,7 +5812,8 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5584
5812
|
columns: input,
|
|
5585
5813
|
ops: nestedOps,
|
|
5586
5814
|
remapValues: (values) => values,
|
|
5587
|
-
write: runUpdate
|
|
5815
|
+
write: runUpdate,
|
|
5816
|
+
context
|
|
5588
5817
|
}) : await runUpdate(executor, input);
|
|
5589
5818
|
if (single && result.length > 1) {
|
|
5590
5819
|
throw new GraphQLError8(`${fieldName}: 'where' matched more than one row!`);
|
|
@@ -5602,7 +5831,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5602
5831
|
args: queryArgs
|
|
5603
5832
|
};
|
|
5604
5833
|
};
|
|
5605
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5834
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
5606
5835
|
const queryArgs = {
|
|
5607
5836
|
updates: {
|
|
5608
5837
|
type: new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(updateManyInput)))
|
|
@@ -5618,6 +5847,8 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5618
5847
|
if (!updates.length) {
|
|
5619
5848
|
throw new GraphQLError8("No updates were provided!");
|
|
5620
5849
|
}
|
|
5850
|
+
const scope = policies?.scope?.(context);
|
|
5851
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
5621
5852
|
const parsedInfo = parseResolveInfo3(info, {
|
|
5622
5853
|
deep: true
|
|
5623
5854
|
});
|
|
@@ -5630,19 +5861,28 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5630
5861
|
table,
|
|
5631
5862
|
pkNames,
|
|
5632
5863
|
parsedInfo,
|
|
5633
|
-
limits
|
|
5864
|
+
limits,
|
|
5865
|
+
scope
|
|
5634
5866
|
});
|
|
5635
5867
|
const entries = updates.map(({ where, set }) => {
|
|
5636
5868
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5637
5869
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
5638
|
-
const input =
|
|
5870
|
+
const input = stripContextValues(
|
|
5871
|
+
remapUpdateInput(split ? split.columns : set, table, tableName),
|
|
5872
|
+
contextColumns
|
|
5873
|
+
);
|
|
5639
5874
|
if (!Object.keys(input).length && !ops) {
|
|
5640
5875
|
throw new GraphQLError8("Unable to update with no values specified!");
|
|
5641
5876
|
}
|
|
5642
5877
|
return {
|
|
5643
5878
|
set: input,
|
|
5644
5879
|
ops,
|
|
5645
|
-
filters:
|
|
5880
|
+
filters: withScope(
|
|
5881
|
+
scope,
|
|
5882
|
+
tableName,
|
|
5883
|
+
table,
|
|
5884
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5885
|
+
)
|
|
5646
5886
|
};
|
|
5647
5887
|
});
|
|
5648
5888
|
const returning = entries.some((entry) => entry.ops) ? nested.withJoinColumns(
|
|
@@ -5656,7 +5896,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5656
5896
|
const perEntry = await executor.transaction(async (tx) => {
|
|
5657
5897
|
const results = [];
|
|
5658
5898
|
for (const entry of entries) {
|
|
5659
|
-
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
|
|
5899
|
+
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops, context) } : entry.set;
|
|
5660
5900
|
const writes = Object.keys(values).length > 0;
|
|
5661
5901
|
let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
|
|
5662
5902
|
if (entry.filters) {
|
|
@@ -5664,7 +5904,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5664
5904
|
}
|
|
5665
5905
|
const rows = await (writes ? query.returning(returning) : query);
|
|
5666
5906
|
if (entry.ops) {
|
|
5667
|
-
await nested.applyChildSide(tx, tableName, entry.ops, rows);
|
|
5907
|
+
await nested.applyChildSide(tx, tableName, entry.ops, rows, context);
|
|
5668
5908
|
}
|
|
5669
5909
|
results.push(rows);
|
|
5670
5910
|
}
|
|
@@ -5693,7 +5933,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5693
5933
|
args: queryArgs
|
|
5694
5934
|
};
|
|
5695
5935
|
};
|
|
5696
|
-
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
5936
|
+
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx, policies) => {
|
|
5697
5937
|
const queryArgs = {
|
|
5698
5938
|
where: {
|
|
5699
5939
|
type: single || requireWhere ? new GraphQLNonNull7(filterArgs) : filterArgs
|
|
@@ -5705,6 +5945,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
5705
5945
|
try {
|
|
5706
5946
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5707
5947
|
const { where } = args;
|
|
5948
|
+
const scope = policies?.scope?.(context);
|
|
5708
5949
|
const parsedInfo = parseResolveInfo3(info, {
|
|
5709
5950
|
deep: true
|
|
5710
5951
|
});
|
|
@@ -5714,7 +5955,12 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
5714
5955
|
selectionCtx
|
|
5715
5956
|
);
|
|
5716
5957
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5717
|
-
const filters =
|
|
5958
|
+
const filters = withScope(
|
|
5959
|
+
scope,
|
|
5960
|
+
tableName,
|
|
5961
|
+
table,
|
|
5962
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
5963
|
+
);
|
|
5718
5964
|
if (single) {
|
|
5719
5965
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5720
5966
|
}
|
|
@@ -5772,12 +6018,16 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5772
6018
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
5773
6019
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
5774
6020
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
6021
|
+
const scopes = options.policies?.scope;
|
|
6022
|
+
const contextValuesOf = options.policies?.contextValues;
|
|
6023
|
+
const policies = bindPolicies(options.policies, filterCtx);
|
|
5775
6024
|
const resolverFactory = createRelationResolverFactory(
|
|
5776
6025
|
db,
|
|
5777
6026
|
tables,
|
|
5778
6027
|
"nulls-largest",
|
|
5779
6028
|
filterCtx,
|
|
5780
|
-
limits
|
|
6029
|
+
limits,
|
|
6030
|
+
scopes
|
|
5781
6031
|
);
|
|
5782
6032
|
const cacheCtx = {
|
|
5783
6033
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -5795,6 +6045,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5795
6045
|
limits,
|
|
5796
6046
|
docs: options.docs ?? {},
|
|
5797
6047
|
primaryKeyOf: (name) => tables[name] ? pgPrimaryKeyPropNames(tables[name]) : [],
|
|
6048
|
+
contextValuesOf,
|
|
5798
6049
|
featureOf
|
|
5799
6050
|
};
|
|
5800
6051
|
const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
|
|
@@ -5805,8 +6056,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5805
6056
|
extractRelationJoinColumns
|
|
5806
6057
|
) : void 0;
|
|
5807
6058
|
const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
|
|
5808
|
-
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
|
|
5809
|
-
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
6059
|
+
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx, scopes, contextValues: contextValuesOf }) : void 0;
|
|
6060
|
+
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx, scopes) : void 0;
|
|
5810
6061
|
const queries = {};
|
|
5811
6062
|
const mutations = {};
|
|
5812
6063
|
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
@@ -5866,7 +6117,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5866
6117
|
typeNameMapper,
|
|
5867
6118
|
filterCtx,
|
|
5868
6119
|
tableFeatures.distinct,
|
|
5869
|
-
limits
|
|
6120
|
+
limits,
|
|
6121
|
+
policies
|
|
5870
6122
|
);
|
|
5871
6123
|
const selectSingleGenerated = generateSelectSingle2(
|
|
5872
6124
|
db,
|
|
@@ -5879,7 +6131,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5879
6131
|
typeName,
|
|
5880
6132
|
typeNameMapper,
|
|
5881
6133
|
filterCtx,
|
|
5882
|
-
limits
|
|
6134
|
+
limits,
|
|
6135
|
+
policies
|
|
5883
6136
|
);
|
|
5884
6137
|
const insertArrGenerated = tableFeatures.insert ? generateInsertArray2(
|
|
5885
6138
|
db,
|
|
@@ -5894,7 +6147,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5894
6147
|
conflictDoNothing,
|
|
5895
6148
|
mutationTxCtx,
|
|
5896
6149
|
nestedRuntime,
|
|
5897
|
-
limits
|
|
6150
|
+
limits,
|
|
6151
|
+
policies
|
|
5898
6152
|
) : void 0;
|
|
5899
6153
|
const insertSingleGenerated = tableFeatures.insert ? generateInsertSingle2(
|
|
5900
6154
|
db,
|
|
@@ -5909,7 +6163,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5909
6163
|
conflictDoNothing,
|
|
5910
6164
|
mutationTxCtx,
|
|
5911
6165
|
nestedRuntime,
|
|
5912
|
-
limits
|
|
6166
|
+
limits,
|
|
6167
|
+
policies
|
|
5913
6168
|
) : void 0;
|
|
5914
6169
|
const uniqueSets = tableFeatures.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig2) : [];
|
|
5915
6170
|
const onConflictInput = tableFeatures.upsert ? generateOnConflictInput({
|
|
@@ -5935,7 +6190,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5935
6190
|
filterCtx,
|
|
5936
6191
|
mutationTxCtx,
|
|
5937
6192
|
nestedRuntime,
|
|
5938
|
-
limits
|
|
6193
|
+
limits,
|
|
6194
|
+
policies
|
|
5939
6195
|
) : void 0;
|
|
5940
6196
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
5941
6197
|
db,
|
|
@@ -5953,7 +6209,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5953
6209
|
filterCtx,
|
|
5954
6210
|
mutationTxCtx,
|
|
5955
6211
|
nestedRuntime,
|
|
5956
|
-
limits
|
|
6212
|
+
limits,
|
|
6213
|
+
policies
|
|
5957
6214
|
) : void 0;
|
|
5958
6215
|
const updateGenerated = tableFeatures.update ? generateUpdate2(
|
|
5959
6216
|
db,
|
|
@@ -5971,7 +6228,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5971
6228
|
filterCtx,
|
|
5972
6229
|
mutationTxCtx,
|
|
5973
6230
|
nestedRuntime,
|
|
5974
|
-
limits
|
|
6231
|
+
limits,
|
|
6232
|
+
policies
|
|
5975
6233
|
) : void 0;
|
|
5976
6234
|
const updateSingleGenerated = tableFeatures.update ? generateUpdate2(
|
|
5977
6235
|
db,
|
|
@@ -5989,7 +6247,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5989
6247
|
filterCtx,
|
|
5990
6248
|
mutationTxCtx,
|
|
5991
6249
|
nestedRuntime,
|
|
5992
|
-
limits
|
|
6250
|
+
limits,
|
|
6251
|
+
policies
|
|
5993
6252
|
) : void 0;
|
|
5994
6253
|
const updateManyInput = tableFeatures.update && tableFeatures.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
5995
6254
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -6005,7 +6264,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
6005
6264
|
filterCtx,
|
|
6006
6265
|
mutationTxCtx,
|
|
6007
6266
|
nestedRuntime,
|
|
6008
|
-
limits
|
|
6267
|
+
limits,
|
|
6268
|
+
policies
|
|
6009
6269
|
) : void 0;
|
|
6010
6270
|
const deleteGenerated = tableFeatures.delete ? generateDelete2(
|
|
6011
6271
|
db,
|
|
@@ -6018,7 +6278,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
6018
6278
|
tableFeatures.requireWhere,
|
|
6019
6279
|
filterCtx,
|
|
6020
6280
|
{ tableName, relationMap: namedRelations, tables },
|
|
6021
|
-
mutationTxCtx
|
|
6281
|
+
mutationTxCtx,
|
|
6282
|
+
policies
|
|
6022
6283
|
) : void 0;
|
|
6023
6284
|
const deleteSingleGenerated = tableFeatures.delete ? generateDelete2(
|
|
6024
6285
|
db,
|
|
@@ -6031,7 +6292,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
6031
6292
|
tableFeatures.requireWhere,
|
|
6032
6293
|
filterCtx,
|
|
6033
6294
|
{ tableName, relationMap: namedRelations, tables },
|
|
6034
|
-
mutationTxCtx
|
|
6295
|
+
mutationTxCtx,
|
|
6296
|
+
policies
|
|
6035
6297
|
) : void 0;
|
|
6036
6298
|
const updateCountGenerated = tableFeatures.update && tableFeatures.countMutations ? generateWriteCount({
|
|
6037
6299
|
db,
|
|
@@ -6065,7 +6327,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
6065
6327
|
typeName,
|
|
6066
6328
|
aggregateFieldName,
|
|
6067
6329
|
tableFilters,
|
|
6068
|
-
filterCtx
|
|
6330
|
+
filterCtx,
|
|
6331
|
+
scopes
|
|
6069
6332
|
) : void 0;
|
|
6070
6333
|
const groupByType = tableFeatures.aggregates && tableFeatures.groupBy ? generateGroupByType(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
6071
6334
|
const groupByEnum = groupByType ? generateGroupByEnum(schema[tableName], tableName, typeName) : void 0;
|
|
@@ -6079,7 +6342,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
6079
6342
|
tableFilters,
|
|
6080
6343
|
groupByEnum,
|
|
6081
6344
|
havingInput,
|
|
6082
|
-
filterCtx
|
|
6345
|
+
filterCtx,
|
|
6346
|
+
scopes
|
|
6083
6347
|
) : void 0;
|
|
6084
6348
|
queries[selectArrGenerated.name] = {
|
|
6085
6349
|
type: selectArrOutput,
|
|
@@ -6286,7 +6550,7 @@ import {
|
|
|
6286
6550
|
GraphQLNonNull as GraphQLNonNull8
|
|
6287
6551
|
} from "graphql";
|
|
6288
6552
|
import { parseResolveInfo as parseResolveInfo4 } from "graphql-parse-resolve-info";
|
|
6289
|
-
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
6553
|
+
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits, policies) => {
|
|
6290
6554
|
const queryBase = db.query[tableName];
|
|
6291
6555
|
if (!queryBase) {
|
|
6292
6556
|
throw new Error(
|
|
@@ -6323,6 +6587,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
6323
6587
|
limits,
|
|
6324
6588
|
pkNames,
|
|
6325
6589
|
db: executor,
|
|
6590
|
+
scope: policies?.scope?.(context),
|
|
6326
6591
|
// SQLite sorts NULLs as the smallest values (first in ASC).
|
|
6327
6592
|
nullOrdering: "nulls-smallest"
|
|
6328
6593
|
});
|
|
@@ -6333,7 +6598,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
6333
6598
|
args: queryArgs
|
|
6334
6599
|
};
|
|
6335
6600
|
};
|
|
6336
|
-
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
6601
|
+
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits, policies) => {
|
|
6337
6602
|
const queryBase = db.query[tableName];
|
|
6338
6603
|
if (!queryBase) {
|
|
6339
6604
|
throw new Error(
|
|
@@ -6363,7 +6628,8 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
6363
6628
|
filterCtx,
|
|
6364
6629
|
limits,
|
|
6365
6630
|
pkNames,
|
|
6366
|
-
db: executor
|
|
6631
|
+
db: executor,
|
|
6632
|
+
scope: policies?.scope?.(context)
|
|
6367
6633
|
});
|
|
6368
6634
|
} catch (e) {
|
|
6369
6635
|
throw toGraphQLError(e);
|
|
@@ -6373,7 +6639,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
6373
6639
|
};
|
|
6374
6640
|
};
|
|
6375
6641
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig3);
|
|
6376
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
6642
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies) => {
|
|
6377
6643
|
const queryArgs = {
|
|
6378
6644
|
values: {
|
|
6379
6645
|
type: new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(baseType)))
|
|
@@ -6390,7 +6656,13 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
6390
6656
|
}
|
|
6391
6657
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
6392
6658
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
6393
|
-
const
|
|
6659
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
6660
|
+
const scope = policies?.scope?.(context);
|
|
6661
|
+
const input = nestedEntries ? [] : applyContextValuesAll(
|
|
6662
|
+
remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table),
|
|
6663
|
+
contextColumns,
|
|
6664
|
+
context
|
|
6665
|
+
);
|
|
6394
6666
|
const parsedInfo = parseResolveInfo4(info, {
|
|
6395
6667
|
deep: true
|
|
6396
6668
|
});
|
|
@@ -6403,7 +6675,8 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
6403
6675
|
table,
|
|
6404
6676
|
pkNames,
|
|
6405
6677
|
parsedInfo,
|
|
6406
|
-
limits
|
|
6678
|
+
limits,
|
|
6679
|
+
scope
|
|
6407
6680
|
});
|
|
6408
6681
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
6409
6682
|
const runInsert = async (target, values) => {
|
|
@@ -6418,8 +6691,9 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
6418
6691
|
runtime: nested,
|
|
6419
6692
|
tableName,
|
|
6420
6693
|
entries: nestedEntries,
|
|
6421
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
6422
|
-
write: (tx, values) => runInsert(tx, [values])
|
|
6694
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
6695
|
+
write: (tx, values) => runInsert(tx, [values]),
|
|
6696
|
+
context
|
|
6423
6697
|
}) : await runInsert(executor, input);
|
|
6424
6698
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
6425
6699
|
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
@@ -6431,7 +6705,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
6431
6705
|
args: queryArgs
|
|
6432
6706
|
};
|
|
6433
6707
|
};
|
|
6434
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
6708
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies) => {
|
|
6435
6709
|
const queryArgs = {
|
|
6436
6710
|
values: {
|
|
6437
6711
|
type: new GraphQLNonNull8(baseType)
|
|
@@ -6445,7 +6719,13 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
6445
6719
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
6446
6720
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
|
|
6447
6721
|
const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
|
|
6448
|
-
const
|
|
6722
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
6723
|
+
const scope = policies?.scope?.(context);
|
|
6724
|
+
const input = nestedEntry ? {} : applyContextValues(
|
|
6725
|
+
remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table),
|
|
6726
|
+
contextColumns,
|
|
6727
|
+
context
|
|
6728
|
+
);
|
|
6449
6729
|
const parsedInfo = parseResolveInfo4(info, {
|
|
6450
6730
|
deep: true
|
|
6451
6731
|
});
|
|
@@ -6458,7 +6738,8 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
6458
6738
|
table,
|
|
6459
6739
|
pkNames,
|
|
6460
6740
|
parsedInfo,
|
|
6461
|
-
limits
|
|
6741
|
+
limits,
|
|
6742
|
+
scope
|
|
6462
6743
|
});
|
|
6463
6744
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
6464
6745
|
const runInsert = async (target, values) => {
|
|
@@ -6473,8 +6754,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
6473
6754
|
runtime: nested,
|
|
6474
6755
|
tableName,
|
|
6475
6756
|
entries: [nestedEntry],
|
|
6476
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
6477
|
-
write: runInsert
|
|
6757
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
6758
|
+
write: runInsert,
|
|
6759
|
+
context
|
|
6478
6760
|
}) : await runInsert(executor, input);
|
|
6479
6761
|
if (!result[0]) {
|
|
6480
6762
|
if (!conflictDoNothing) {
|
|
@@ -6492,7 +6774,7 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
6492
6774
|
args: queryArgs
|
|
6493
6775
|
};
|
|
6494
6776
|
};
|
|
6495
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
6777
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
6496
6778
|
const queryArgs = {
|
|
6497
6779
|
values: {
|
|
6498
6780
|
type: single ? new GraphQLNonNull8(baseType) : new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(baseType)))
|
|
@@ -6514,7 +6796,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
6514
6796
|
}
|
|
6515
6797
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
6516
6798
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
6517
|
-
const
|
|
6799
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
6800
|
+
const scope = policies?.scope?.(context);
|
|
6801
|
+
const input = nestedEntries ? [] : applyContextValuesAll(
|
|
6802
|
+
remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table),
|
|
6803
|
+
contextColumns,
|
|
6804
|
+
context
|
|
6805
|
+
);
|
|
6518
6806
|
const parsedInfo = parseResolveInfo4(info, { deep: true });
|
|
6519
6807
|
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
6520
6808
|
relationMap,
|
|
@@ -6525,7 +6813,8 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
6525
6813
|
table,
|
|
6526
6814
|
pkNames,
|
|
6527
6815
|
parsedInfo,
|
|
6528
|
-
limits
|
|
6816
|
+
limits,
|
|
6817
|
+
scope
|
|
6529
6818
|
});
|
|
6530
6819
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
6531
6820
|
const runUpsert = async (target, values) => {
|
|
@@ -6540,7 +6829,8 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
6540
6829
|
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
6541
6830
|
});
|
|
6542
6831
|
let query = target.insert(table).values(values).returning(returning);
|
|
6543
|
-
|
|
6832
|
+
const setWhere = withScope(scope, tableName, table, plan.setWhere);
|
|
6833
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere });
|
|
6544
6834
|
return await query;
|
|
6545
6835
|
};
|
|
6546
6836
|
const result = nestedEntries ? await writeWithNestedOps({
|
|
@@ -6548,8 +6838,9 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
6548
6838
|
runtime: nested,
|
|
6549
6839
|
tableName,
|
|
6550
6840
|
entries: nestedEntries,
|
|
6551
|
-
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
6552
|
-
write: (tx, values) => runUpsert(tx, [values])
|
|
6841
|
+
remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
|
|
6842
|
+
write: (tx, values) => runUpsert(tx, [values]),
|
|
6843
|
+
context
|
|
6553
6844
|
}) : await runUpsert(executor, input);
|
|
6554
6845
|
if (single && !result[0]) {
|
|
6555
6846
|
return void 0;
|
|
@@ -6564,7 +6855,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
6564
6855
|
args: queryArgs
|
|
6565
6856
|
};
|
|
6566
6857
|
};
|
|
6567
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
6858
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
6568
6859
|
const queryArgs = {
|
|
6569
6860
|
set: {
|
|
6570
6861
|
type: new GraphQLNonNull8(setArgs)
|
|
@@ -6580,6 +6871,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
6580
6871
|
try {
|
|
6581
6872
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
6582
6873
|
const { where, set } = args;
|
|
6874
|
+
const scope = policies?.scope?.(context);
|
|
6583
6875
|
const parsedInfo = parseResolveInfo4(info, {
|
|
6584
6876
|
deep: true
|
|
6585
6877
|
});
|
|
@@ -6592,16 +6884,25 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
6592
6884
|
table,
|
|
6593
6885
|
pkNames,
|
|
6594
6886
|
parsedInfo,
|
|
6595
|
-
limits
|
|
6887
|
+
limits,
|
|
6888
|
+
scope
|
|
6596
6889
|
});
|
|
6597
6890
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
6598
6891
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
6599
|
-
const input =
|
|
6892
|
+
const input = stripContextValues(
|
|
6893
|
+
remapUpdateInput(entry ? entry.columns : set, table, tableName),
|
|
6894
|
+
policies?.contextValues?.(tableName)
|
|
6895
|
+
);
|
|
6600
6896
|
if (!Object.keys(input).length && !nestedOps) {
|
|
6601
6897
|
throw new GraphQLError9("Unable to update with no values specified!");
|
|
6602
6898
|
}
|
|
6603
6899
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
6604
|
-
const filters =
|
|
6900
|
+
const filters = withScope(
|
|
6901
|
+
scope,
|
|
6902
|
+
tableName,
|
|
6903
|
+
table,
|
|
6904
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
6905
|
+
);
|
|
6605
6906
|
if (single) {
|
|
6606
6907
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
6607
6908
|
}
|
|
@@ -6621,7 +6922,8 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
6621
6922
|
columns: input,
|
|
6622
6923
|
ops: nestedOps,
|
|
6623
6924
|
remapValues: (values) => values,
|
|
6624
|
-
write: runUpdate
|
|
6925
|
+
write: runUpdate,
|
|
6926
|
+
context
|
|
6625
6927
|
}) : await runUpdate(executor, input);
|
|
6626
6928
|
if (single && result.length > 1) {
|
|
6627
6929
|
throw new GraphQLError9(`${fieldName}: 'where' matched more than one row!`);
|
|
@@ -6639,7 +6941,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
6639
6941
|
args: queryArgs
|
|
6640
6942
|
};
|
|
6641
6943
|
};
|
|
6642
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
6944
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits, policies) => {
|
|
6643
6945
|
const queryArgs = {
|
|
6644
6946
|
updates: {
|
|
6645
6947
|
type: new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(updateManyInput)))
|
|
@@ -6655,6 +6957,8 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
6655
6957
|
if (!updates.length) {
|
|
6656
6958
|
throw new GraphQLError9("No updates were provided!");
|
|
6657
6959
|
}
|
|
6960
|
+
const scope = policies?.scope?.(context);
|
|
6961
|
+
const contextColumns = policies?.contextValues?.(tableName);
|
|
6658
6962
|
const parsedInfo = parseResolveInfo4(info, {
|
|
6659
6963
|
deep: true
|
|
6660
6964
|
});
|
|
@@ -6667,19 +6971,28 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
6667
6971
|
table,
|
|
6668
6972
|
pkNames,
|
|
6669
6973
|
parsedInfo,
|
|
6670
|
-
limits
|
|
6974
|
+
limits,
|
|
6975
|
+
scope
|
|
6671
6976
|
});
|
|
6672
6977
|
const entries = updates.map(({ where, set }) => {
|
|
6673
6978
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
6674
6979
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
6675
|
-
const input =
|
|
6980
|
+
const input = stripContextValues(
|
|
6981
|
+
remapUpdateInput(split ? split.columns : set, table, tableName),
|
|
6982
|
+
contextColumns
|
|
6983
|
+
);
|
|
6676
6984
|
if (!Object.keys(input).length && !ops) {
|
|
6677
6985
|
throw new GraphQLError9("Unable to update with no values specified!");
|
|
6678
6986
|
}
|
|
6679
6987
|
return {
|
|
6680
6988
|
set: input,
|
|
6681
6989
|
ops,
|
|
6682
|
-
filters:
|
|
6990
|
+
filters: withScope(
|
|
6991
|
+
scope,
|
|
6992
|
+
tableName,
|
|
6993
|
+
table,
|
|
6994
|
+
where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
6995
|
+
)
|
|
6683
6996
|
};
|
|
6684
6997
|
});
|
|
6685
6998
|
const anyNested = entries.some((entry) => entry.ops);
|
|
@@ -6697,7 +7010,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
6697
7010
|
return query.returning(returning).all();
|
|
6698
7011
|
};
|
|
6699
7012
|
const runNestedEntry = async (tx, entry) => {
|
|
6700
|
-
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
|
|
7013
|
+
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops, context) } : entry.set;
|
|
6701
7014
|
const writes = Object.keys(values).length > 0;
|
|
6702
7015
|
let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
|
|
6703
7016
|
if (entry.filters) {
|
|
@@ -6705,7 +7018,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
6705
7018
|
}
|
|
6706
7019
|
const rows = await (writes ? query.returning(returning) : query);
|
|
6707
7020
|
if (entry.ops) {
|
|
6708
|
-
await nested.applyChildSide(tx, tableName, entry.ops, rows);
|
|
7021
|
+
await nested.applyChildSide(tx, tableName, entry.ops, rows, context);
|
|
6709
7022
|
}
|
|
6710
7023
|
return rows;
|
|
6711
7024
|
};
|
|
@@ -6758,7 +7071,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
6758
7071
|
args: queryArgs
|
|
6759
7072
|
};
|
|
6760
7073
|
};
|
|
6761
|
-
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
7074
|
+
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx, policies) => {
|
|
6762
7075
|
const queryArgs = {
|
|
6763
7076
|
where: {
|
|
6764
7077
|
type: single || requireWhere ? new GraphQLNonNull8(filterArgs) : filterArgs
|
|
@@ -6770,6 +7083,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
6770
7083
|
try {
|
|
6771
7084
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
6772
7085
|
const { where } = args;
|
|
7086
|
+
const scope = policies?.scope?.(context);
|
|
6773
7087
|
const parsedInfo = parseResolveInfo4(info, {
|
|
6774
7088
|
deep: true
|
|
6775
7089
|
});
|
|
@@ -6779,7 +7093,12 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
6779
7093
|
selectionCtx
|
|
6780
7094
|
);
|
|
6781
7095
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
6782
|
-
const filters =
|
|
7096
|
+
const filters = withScope(
|
|
7097
|
+
scope,
|
|
7098
|
+
tableName,
|
|
7099
|
+
table,
|
|
7100
|
+
single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0
|
|
7101
|
+
);
|
|
6783
7102
|
if (single) {
|
|
6784
7103
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
6785
7104
|
}
|
|
@@ -6838,12 +7157,16 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6838
7157
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
6839
7158
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
6840
7159
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
7160
|
+
const scopes = options.policies?.scope;
|
|
7161
|
+
const contextValuesOf = options.policies?.contextValues;
|
|
7162
|
+
const policies = bindPolicies(options.policies, filterCtx);
|
|
6841
7163
|
const resolverFactory = createRelationResolverFactory(
|
|
6842
7164
|
db,
|
|
6843
7165
|
tables,
|
|
6844
7166
|
"nulls-smallest",
|
|
6845
7167
|
filterCtx,
|
|
6846
|
-
limits
|
|
7168
|
+
limits,
|
|
7169
|
+
scopes
|
|
6847
7170
|
);
|
|
6848
7171
|
const cacheCtx = {
|
|
6849
7172
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -6861,6 +7184,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6861
7184
|
limits,
|
|
6862
7185
|
docs: options.docs ?? {},
|
|
6863
7186
|
primaryKeyOf: (name) => tables[name] ? sqlitePrimaryKeyPropNames(tables[name]) : [],
|
|
7187
|
+
contextValuesOf,
|
|
6864
7188
|
featureOf
|
|
6865
7189
|
};
|
|
6866
7190
|
if (features.nestedWrites && db.resultKind === "sync") {
|
|
@@ -6876,8 +7200,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6876
7200
|
extractRelationJoinColumns
|
|
6877
7201
|
) : void 0;
|
|
6878
7202
|
const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
|
|
6879
|
-
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
|
|
6880
|
-
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
7203
|
+
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx, scopes, contextValues: contextValuesOf }) : void 0;
|
|
7204
|
+
const relationAggregateFactory = anyTable("relationAggregates") ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx, scopes) : void 0;
|
|
6881
7205
|
const queries = {};
|
|
6882
7206
|
const mutations = {};
|
|
6883
7207
|
if (options.transactions && db.resultKind === "sync") {
|
|
@@ -6942,7 +7266,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6942
7266
|
typeNameMapper,
|
|
6943
7267
|
filterCtx,
|
|
6944
7268
|
tableFeatures.distinct,
|
|
6945
|
-
limits
|
|
7269
|
+
limits,
|
|
7270
|
+
policies
|
|
6946
7271
|
);
|
|
6947
7272
|
const selectSingleGenerated = generateSelectSingle3(
|
|
6948
7273
|
db,
|
|
@@ -6955,7 +7280,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6955
7280
|
typeName,
|
|
6956
7281
|
typeNameMapper,
|
|
6957
7282
|
filterCtx,
|
|
6958
|
-
limits
|
|
7283
|
+
limits,
|
|
7284
|
+
policies
|
|
6959
7285
|
);
|
|
6960
7286
|
const insertArrGenerated = tableFeatures.insert ? generateInsertArray3(
|
|
6961
7287
|
db,
|
|
@@ -6970,7 +7296,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6970
7296
|
conflictDoNothing,
|
|
6971
7297
|
mutationTxCtx,
|
|
6972
7298
|
nestedRuntime,
|
|
6973
|
-
limits
|
|
7299
|
+
limits,
|
|
7300
|
+
policies
|
|
6974
7301
|
) : void 0;
|
|
6975
7302
|
const insertSingleGenerated = tableFeatures.insert ? generateInsertSingle3(
|
|
6976
7303
|
db,
|
|
@@ -6985,7 +7312,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6985
7312
|
conflictDoNothing,
|
|
6986
7313
|
mutationTxCtx,
|
|
6987
7314
|
nestedRuntime,
|
|
6988
|
-
limits
|
|
7315
|
+
limits,
|
|
7316
|
+
policies
|
|
6989
7317
|
) : void 0;
|
|
6990
7318
|
const uniqueSets = tableFeatures.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig3) : [];
|
|
6991
7319
|
const onConflictInput = tableFeatures.upsert ? generateOnConflictInput({
|
|
@@ -7011,7 +7339,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7011
7339
|
filterCtx,
|
|
7012
7340
|
mutationTxCtx,
|
|
7013
7341
|
nestedRuntime,
|
|
7014
|
-
limits
|
|
7342
|
+
limits,
|
|
7343
|
+
policies
|
|
7015
7344
|
) : void 0;
|
|
7016
7345
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
7017
7346
|
db,
|
|
@@ -7029,7 +7358,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7029
7358
|
filterCtx,
|
|
7030
7359
|
mutationTxCtx,
|
|
7031
7360
|
nestedRuntime,
|
|
7032
|
-
limits
|
|
7361
|
+
limits,
|
|
7362
|
+
policies
|
|
7033
7363
|
) : void 0;
|
|
7034
7364
|
const updateGenerated = tableFeatures.update ? generateUpdate3(
|
|
7035
7365
|
db,
|
|
@@ -7047,7 +7377,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7047
7377
|
filterCtx,
|
|
7048
7378
|
mutationTxCtx,
|
|
7049
7379
|
nestedRuntime,
|
|
7050
|
-
limits
|
|
7380
|
+
limits,
|
|
7381
|
+
policies
|
|
7051
7382
|
) : void 0;
|
|
7052
7383
|
const updateSingleGenerated = tableFeatures.update ? generateUpdate3(
|
|
7053
7384
|
db,
|
|
@@ -7065,7 +7396,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7065
7396
|
filterCtx,
|
|
7066
7397
|
mutationTxCtx,
|
|
7067
7398
|
nestedRuntime,
|
|
7068
|
-
limits
|
|
7399
|
+
limits,
|
|
7400
|
+
policies
|
|
7069
7401
|
) : void 0;
|
|
7070
7402
|
const updateManyInput = tableFeatures.update && tableFeatures.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
7071
7403
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -7081,7 +7413,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7081
7413
|
filterCtx,
|
|
7082
7414
|
mutationTxCtx,
|
|
7083
7415
|
nestedRuntime,
|
|
7084
|
-
limits
|
|
7416
|
+
limits,
|
|
7417
|
+
policies
|
|
7085
7418
|
) : void 0;
|
|
7086
7419
|
const deleteGenerated = tableFeatures.delete ? generateDelete3(
|
|
7087
7420
|
db,
|
|
@@ -7094,7 +7427,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7094
7427
|
tableFeatures.requireWhere,
|
|
7095
7428
|
filterCtx,
|
|
7096
7429
|
{ tableName, relationMap: namedRelations, tables },
|
|
7097
|
-
mutationTxCtx
|
|
7430
|
+
mutationTxCtx,
|
|
7431
|
+
policies
|
|
7098
7432
|
) : void 0;
|
|
7099
7433
|
const deleteSingleGenerated = tableFeatures.delete ? generateDelete3(
|
|
7100
7434
|
db,
|
|
@@ -7107,7 +7441,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7107
7441
|
tableFeatures.requireWhere,
|
|
7108
7442
|
filterCtx,
|
|
7109
7443
|
{ tableName, relationMap: namedRelations, tables },
|
|
7110
|
-
mutationTxCtx
|
|
7444
|
+
mutationTxCtx,
|
|
7445
|
+
policies
|
|
7111
7446
|
) : void 0;
|
|
7112
7447
|
const updateCountGenerated = tableFeatures.update && tableFeatures.countMutations ? generateWriteCount({
|
|
7113
7448
|
db,
|
|
@@ -7141,7 +7476,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7141
7476
|
typeName,
|
|
7142
7477
|
aggregateFieldName,
|
|
7143
7478
|
tableFilters,
|
|
7144
|
-
filterCtx
|
|
7479
|
+
filterCtx,
|
|
7480
|
+
scopes
|
|
7145
7481
|
) : void 0;
|
|
7146
7482
|
const groupByType = tableFeatures.aggregates && tableFeatures.groupBy ? generateGroupByType(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
7147
7483
|
const groupByEnum = groupByType ? generateGroupByEnum(schema[tableName], tableName, typeName) : void 0;
|
|
@@ -7155,7 +7491,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
7155
7491
|
tableFilters,
|
|
7156
7492
|
groupByEnum,
|
|
7157
7493
|
havingInput,
|
|
7158
|
-
filterCtx
|
|
7494
|
+
filterCtx,
|
|
7495
|
+
scopes
|
|
7159
7496
|
) : void 0;
|
|
7160
7497
|
queries[selectArrGenerated.name] = {
|
|
7161
7498
|
type: selectArrOutput,
|
|
@@ -7547,6 +7884,43 @@ var buildSchema = (db, config) => {
|
|
|
7547
7884
|
limitPolicyCache.set(tableName, resolved);
|
|
7548
7885
|
return resolved;
|
|
7549
7886
|
} : void 0;
|
|
7887
|
+
const scopeConfig = config?.scope;
|
|
7888
|
+
const contextValuesConfig = config?.contextValues;
|
|
7889
|
+
if (scopeConfig || contextValuesConfig) {
|
|
7890
|
+
const tableNames = new Set(tableKeys);
|
|
7891
|
+
for (const [tableName, hook] of Object.entries(scopeConfig ?? {})) {
|
|
7892
|
+
if (!tableNames.has(tableName)) {
|
|
7893
|
+
throw new Error(
|
|
7894
|
+
`Drizzle-GraphQL Error: config.scope names '${tableName}', which is not a table in the Drizzle schema.`
|
|
7895
|
+
);
|
|
7896
|
+
}
|
|
7897
|
+
if (typeof hook !== "function") {
|
|
7898
|
+
throw new Error(`Drizzle-GraphQL Error: config.scope.${tableName} must be a function.`);
|
|
7899
|
+
}
|
|
7900
|
+
}
|
|
7901
|
+
for (const [tableName, columnHooks] of Object.entries(contextValuesConfig ?? {})) {
|
|
7902
|
+
if (!tableNames.has(tableName)) {
|
|
7903
|
+
throw new Error(
|
|
7904
|
+
`Drizzle-GraphQL Error: config.contextValues names '${tableName}', which is not a table in the Drizzle schema.`
|
|
7905
|
+
);
|
|
7906
|
+
}
|
|
7907
|
+
const columns = getColumns6(schema[tableName]);
|
|
7908
|
+
for (const [columnName, hook] of Object.entries(columnHooks)) {
|
|
7909
|
+
if (!columns[columnName]) {
|
|
7910
|
+
throw new Error(
|
|
7911
|
+
`Drizzle-GraphQL Error: config.contextValues names '${tableName}.${columnName}', which is not a column of that table.`
|
|
7912
|
+
);
|
|
7913
|
+
}
|
|
7914
|
+
if (typeof hook !== "function") {
|
|
7915
|
+
throw new Error(`Drizzle-GraphQL Error: config.contextValues.${tableName}.${columnName} must be a function.`);
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
}
|
|
7920
|
+
const policies = scopeConfig || contextValuesConfig ? {
|
|
7921
|
+
scope: scopeConfig ? (tableName) => scopeConfig[tableName] : void 0,
|
|
7922
|
+
contextValues: contextValuesConfig ? (tableName) => contextValuesConfig[tableName] : void 0
|
|
7923
|
+
} : void 0;
|
|
7550
7924
|
const exclude = config?.exclude;
|
|
7551
7925
|
if (exclude) {
|
|
7552
7926
|
const tableNames = new Set(tableKeys);
|
|
@@ -7664,6 +8038,7 @@ var buildSchema = (db, config) => {
|
|
|
7664
8038
|
enumNameMapper: config?.enumNameMapper,
|
|
7665
8039
|
transactions,
|
|
7666
8040
|
limits,
|
|
8041
|
+
policies,
|
|
7667
8042
|
exclude,
|
|
7668
8043
|
docs: {
|
|
7669
8044
|
describeColumn: config?.describeColumn,
|