@pothos/plugin-drizzle 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +351 -0
- package/README.md +784 -221
- package/dts/connection-helpers.d.ts +18 -8
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/drizzle-field-builder.d.ts +4 -11
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/model-loader.d.ts +18 -17
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/types.d.ts +81 -20
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/adapter.d.ts +39 -0
- package/dts/utils/adapter.d.ts.map +1 -0
- package/dts/utils/await-selections.d.ts +12 -0
- package/dts/utils/await-selections.d.ts.map +1 -0
- package/dts/utils/config.d.ts +23 -3
- package/dts/utils/config.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +6 -6
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/map-query.d.ts +22 -21
- package/dts/utils/map-query.d.ts.map +1 -1
- package/dts/utils/path-info.d.ts +13 -0
- package/dts/utils/path-info.d.ts.map +1 -0
- package/dts/utils/relation-filter.d.ts +48 -0
- package/dts/utils/relation-filter.d.ts.map +1 -0
- package/dts/utils/selections.d.ts +2 -21
- package/dts/utils/selections.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +18 -8
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js +52 -19
- package/esm/connection-helpers.js.map +1 -1
- package/esm/drizzle-field-builder.d.ts +4 -11
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +138 -96
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/field-builder.js +61 -47
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts.map +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +37 -61
- package/esm/index.js.map +1 -1
- package/esm/model-loader.d.ts +18 -17
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +76 -45
- package/esm/model-loader.js.map +1 -1
- package/esm/schema-builder.js +40 -149
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +81 -20
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -0
- package/esm/types.js.map +1 -1
- package/esm/utils/adapter.d.ts +39 -0
- package/esm/utils/adapter.d.ts.map +1 -0
- package/esm/utils/adapter.js +137 -0
- package/esm/utils/adapter.js.map +1 -0
- package/esm/utils/await-selections.d.ts +12 -0
- package/esm/utils/await-selections.d.ts.map +1 -0
- package/esm/utils/await-selections.js +19 -0
- package/esm/utils/await-selections.js.map +1 -0
- package/esm/utils/config.d.ts +23 -3
- package/esm/utils/config.d.ts.map +1 -1
- package/esm/utils/config.js +1 -4
- package/esm/utils/config.js.map +1 -1
- package/esm/utils/cursors.d.ts +6 -6
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +55 -90
- package/esm/utils/cursors.js.map +1 -1
- package/esm/utils/map-query.d.ts +22 -21
- package/esm/utils/map-query.d.ts.map +1 -1
- package/esm/utils/map-query.js +40 -336
- package/esm/utils/map-query.js.map +1 -1
- package/esm/utils/path-info.d.ts +13 -0
- package/esm/utils/path-info.d.ts.map +1 -0
- package/esm/utils/path-info.js +37 -0
- package/esm/utils/path-info.js.map +1 -0
- package/esm/utils/relation-filter.d.ts +48 -0
- package/esm/utils/relation-filter.d.ts.map +1 -0
- package/esm/utils/relation-filter.js +92 -0
- package/esm/utils/relation-filter.js.map +1 -0
- package/esm/utils/selections.d.ts +2 -21
- package/esm/utils/selections.d.ts.map +1 -1
- package/esm/utils/selections.js +1 -133
- package/esm/utils/selections.js.map +1 -1
- package/lib/connection-helpers.js +51 -18
- package/lib/connection-helpers.js.map +1 -1
- package/lib/drizzle-field-builder.js +136 -94
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/field-builder.js +58 -44
- package/lib/field-builder.js.map +1 -1
- package/lib/index.js +36 -60
- package/lib/index.js.map +1 -1
- package/lib/model-loader.js +76 -45
- package/lib/model-loader.js.map +1 -1
- package/lib/schema-builder.js +40 -149
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js +4 -0
- package/lib/types.js.map +1 -1
- package/lib/utils/adapter.js +147 -0
- package/lib/utils/adapter.js.map +1 -0
- package/lib/utils/await-selections.js +20 -0
- package/lib/utils/await-selections.js.map +1 -0
- package/lib/utils/config.js +1 -4
- package/lib/utils/config.js.map +1 -1
- package/lib/utils/cursors.js +47 -88
- package/lib/utils/cursors.js.map +1 -1
- package/lib/utils/map-query.js +28 -341
- package/lib/utils/map-query.js.map +1 -1
- package/lib/utils/path-info.js +39 -0
- package/lib/utils/path-info.js.map +1 -0
- package/lib/utils/relation-filter.js +91 -0
- package/lib/utils/relation-filter.js.map +1 -0
- package/lib/utils/selections.js +3 -158
- package/lib/utils/selections.js.map +1 -1
- package/package.json +8 -6
- package/src/connection-helpers.ts +167 -53
- package/src/drizzle-field-builder.ts +296 -176
- package/src/field-builder.ts +110 -77
- package/src/global-types.ts +0 -32
- package/src/index.ts +42 -68
- package/src/model-loader.ts +110 -71
- package/src/schema-builder.ts +76 -169
- package/src/types.ts +176 -44
- package/src/utils/adapter.ts +197 -0
- package/src/utils/await-selections.ts +31 -0
- package/src/utils/config.ts +1 -5
- package/src/utils/cursors.ts +53 -81
- package/src/utils/map-query.ts +51 -708
- package/src/utils/path-info.ts +40 -0
- package/src/utils/relation-filter.ts +185 -0
- package/src/utils/selections.ts +2 -207
- package/dts/utils/deep-equal.d.ts +0 -2
- package/dts/utils/deep-equal.d.ts.map +0 -1
- package/dts/utils/drizzle-graphql.d.ts +0 -2
- package/dts/utils/drizzle-graphql.d.ts.map +0 -1
- package/dts/utils/loader-map.d.ts +0 -11
- package/dts/utils/loader-map.d.ts.map +0 -1
- package/dts/utils/usage.d.ts +0 -5
- package/dts/utils/usage.d.ts.map +0 -1
- package/esm/utils/deep-equal.d.ts +0 -2
- package/esm/utils/deep-equal.d.ts.map +0 -1
- package/esm/utils/deep-equal.js +0 -45
- package/esm/utils/deep-equal.js.map +0 -1
- package/esm/utils/drizzle-graphql.d.ts +0 -2
- package/esm/utils/drizzle-graphql.d.ts.map +0 -1
- package/esm/utils/drizzle-graphql.js +0 -232
- package/esm/utils/drizzle-graphql.js.map +0 -1
- package/esm/utils/loader-map.d.ts +0 -11
- package/esm/utils/loader-map.d.ts.map +0 -1
- package/esm/utils/loader-map.js +0 -35
- package/esm/utils/loader-map.js.map +0 -1
- package/esm/utils/usage.d.ts +0 -5
- package/esm/utils/usage.d.ts.map +0 -1
- package/esm/utils/usage.js +0 -59
- package/esm/utils/usage.js.map +0 -1
- package/lib/utils/deep-equal.js +0 -55
- package/lib/utils/deep-equal.js.map +0 -1
- package/lib/utils/drizzle-graphql.js +0 -236
- package/lib/utils/drizzle-graphql.js.map +0 -1
- package/lib/utils/loader-map.js +0 -56
- package/lib/utils/loader-map.js.map +0 -1
- package/lib/utils/usage.js +0 -83
- package/lib/utils/usage.js.map +0 -1
- package/src/utils/deep-equal.ts +0 -57
- package/src/utils/drizzle-graphql.ts +0 -274
- package/src/utils/loader-map.ts +0 -49
- package/src/utils/usage.ts +0 -62
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import type { DBQueryConfig
|
|
2
|
-
import type { PothosDrizzleSchemaConfig } from './config.js';
|
|
3
|
-
import type { LoaderMappings } from './loader-map.js';
|
|
4
|
-
export interface SelectionState {
|
|
5
|
-
table: TableRelationalConfig;
|
|
6
|
-
query: object;
|
|
7
|
-
allColumns: boolean;
|
|
8
|
-
columns: Set<string>;
|
|
9
|
-
with: Map<string, SelectionState>;
|
|
10
|
-
extras: Map<string, NonNullable<SelectionMap['extras']>[string]>;
|
|
11
|
-
mappings: LoaderMappings;
|
|
12
|
-
parent?: SelectionState;
|
|
13
|
-
depth: number;
|
|
14
|
-
skipDeferredFragments: boolean;
|
|
15
|
-
}
|
|
1
|
+
import type { DBQueryConfig } from 'drizzle-orm';
|
|
16
2
|
export type SelectionMap = DBQueryConfig<'one'>;
|
|
3
|
+
/** Drops keys holding `undefined`, so `{ where: cond ? filter : undefined }` reads as `{}`. */
|
|
17
4
|
export declare function omitUndefinedKeys<T extends object>(query: T): T;
|
|
18
|
-
export declare function selectionCompatible(state: SelectionState, selectionMap: SelectionMap | boolean, ignoreQuery?: boolean): boolean;
|
|
19
|
-
export declare function stateCompatible(state: SelectionState, newState: SelectionState, ignoreQuery?: boolean): boolean;
|
|
20
|
-
export declare function mergeState(state: SelectionState, newState: SelectionState): void;
|
|
21
|
-
export declare function createState(table: TableRelationalConfig, skipDeferredFragments: boolean, parent?: SelectionState): SelectionState;
|
|
22
|
-
export declare function mergeSelection(config: PothosDrizzleSchemaConfig, state: SelectionState, selection: SelectionMap | boolean): void;
|
|
23
|
-
export declare function selectionToQuery(config: PothosDrizzleSchemaConfig, state: SelectionState): SelectionMap;
|
|
24
5
|
//# sourceMappingURL=selections.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selections.d.ts","sourceRoot":"","sources":["../../src/utils/selections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selections.d.ts","sourceRoot":"","sources":["../../src/utils/selections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAEhD,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAK/D"}
|
package/esm/utils/selections.js
CHANGED
|
@@ -1,139 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { deepEqual } from './deep-equal.js';
|
|
3
|
-
export function omitUndefinedKeys(query) {
|
|
1
|
+
/** Drops keys holding `undefined`, so `{ where: cond ? filter : undefined }` reads as `{}`. */ export function omitUndefinedKeys(query) {
|
|
4
2
|
const entries = Object.entries(query);
|
|
5
3
|
const defined = entries.filter(([, value])=>value !== undefined);
|
|
6
4
|
return defined.length === entries.length ? query : Object.fromEntries(defined);
|
|
7
5
|
}
|
|
8
|
-
export function selectionCompatible(state, selectionMap, ignoreQuery = false) {
|
|
9
|
-
if (typeof selectionMap === 'boolean') {
|
|
10
|
-
return ignoreQuery || !selectionMap || Object.keys(state.query).length === 0;
|
|
11
|
-
}
|
|
12
|
-
const { with: withSelection, extras, columns: _, ...query } = selectionMap;
|
|
13
|
-
if (withSelection && Object.entries(withSelection).some(([key, value])=>value && state.with.has(key) && // TODO: make sure nested extras are normalized
|
|
14
|
-
!selectionCompatible(state.with.get(key), value))) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (extras && Object.entries(extras).some(([key, value])=>{
|
|
18
|
-
const existing = state.extras.get(key);
|
|
19
|
-
return existing && existing !== value;
|
|
20
|
-
})) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return ignoreQuery || deepEqual(state.query, omitUndefinedKeys(query));
|
|
24
|
-
}
|
|
25
|
-
export function stateCompatible(state, newState, ignoreQuery = false) {
|
|
26
|
-
for (const [name, relationState] of newState.with){
|
|
27
|
-
if (state.with.has(name) && !stateCompatible(state.with.get(name), relationState)) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return ignoreQuery || deepEqual(state.query, newState.query);
|
|
32
|
-
}
|
|
33
|
-
export function mergeState(state, newState) {
|
|
34
|
-
for (const [name, relationState] of newState.with){
|
|
35
|
-
if (state.with.has(name)) {
|
|
36
|
-
mergeState(state.with.get(name), relationState);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!state.allColumns) {
|
|
40
|
-
if (newState.allColumns) {
|
|
41
|
-
state.allColumns = true;
|
|
42
|
-
} else {
|
|
43
|
-
for (const name of newState.columns){
|
|
44
|
-
state.columns.add(name);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
for (const [name, value] of newState.extras){
|
|
49
|
-
state.extras.set(name, value);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export function createState(table, skipDeferredFragments, parent) {
|
|
53
|
-
return {
|
|
54
|
-
table,
|
|
55
|
-
skipDeferredFragments,
|
|
56
|
-
parent,
|
|
57
|
-
query: {},
|
|
58
|
-
columns: new Set(),
|
|
59
|
-
with: new Map(),
|
|
60
|
-
extras: new Map(),
|
|
61
|
-
mappings: {},
|
|
62
|
-
allColumns: false,
|
|
63
|
-
depth: parent ? parent.depth + 1 : 0
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export function mergeSelection(config, state, selection) {
|
|
67
|
-
const { with: withSelection, extras, columns, ...query } = typeof selection === 'boolean' ? selection === true ? {} : {
|
|
68
|
-
columns: {}
|
|
69
|
-
} : selection;
|
|
70
|
-
if (withSelection) {
|
|
71
|
-
for (const [key, value] of Object.entries(withSelection)){
|
|
72
|
-
const relation = state.table.relations[key];
|
|
73
|
-
if (!relation) {
|
|
74
|
-
throw new PothosValidationError(`Relation ${key} does not exist on ${state.table.name}`);
|
|
75
|
-
}
|
|
76
|
-
merge(config.relations[relation.targetTableName], key, value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const normalizedQuery = omitUndefinedKeys(query);
|
|
80
|
-
if (Object.keys(normalizedQuery).length > 0) {
|
|
81
|
-
state.query = normalizedQuery;
|
|
82
|
-
}
|
|
83
|
-
if (extras) {
|
|
84
|
-
for (const [key, value] of Object.entries(extras)){
|
|
85
|
-
state.extras.set(key, value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (state.allColumns) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (columns && !state.allColumns) {
|
|
92
|
-
for (const [key, value] of Object.entries(columns)){
|
|
93
|
-
if (value) {
|
|
94
|
-
state.columns.add(key);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
state.allColumns = true;
|
|
99
|
-
}
|
|
100
|
-
function merge(table, key, value) {
|
|
101
|
-
if (!value) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (state.with.has(key)) {
|
|
105
|
-
mergeSelection(config, state.with.get(key), value);
|
|
106
|
-
} else {
|
|
107
|
-
const relatedState = createState(table, state.skipDeferredFragments, state);
|
|
108
|
-
mergeSelection(config, relatedState, value);
|
|
109
|
-
state.with.set(key, relatedState);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export function selectionToQuery(config, state) {
|
|
114
|
-
const query = {
|
|
115
|
-
...omitUndefinedKeys(state.query),
|
|
116
|
-
columns: undefined,
|
|
117
|
-
with: {},
|
|
118
|
-
extras: {}
|
|
119
|
-
};
|
|
120
|
-
if (!state.allColumns) {
|
|
121
|
-
query.columns = {};
|
|
122
|
-
for (const key of state.columns){
|
|
123
|
-
query.columns[key] = true;
|
|
124
|
-
}
|
|
125
|
-
for (const column of config.getPrimaryKey(state.table.name)){
|
|
126
|
-
const tsName = config.columnToTsName(column);
|
|
127
|
-
query.columns[tsName] = true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
for (const [key, value] of state.extras){
|
|
131
|
-
query.extras[key] = value;
|
|
132
|
-
}
|
|
133
|
-
state.with.forEach((sel, relation)=>{
|
|
134
|
-
query.with[relation] = selectionToQuery(config, sel);
|
|
135
|
-
});
|
|
136
|
-
return query;
|
|
137
|
-
}
|
|
138
6
|
|
|
139
7
|
//# sourceMappingURL=selections.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/selections.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/selections.ts"],"names":["omitUndefinedKeys","query","entries","Object","defined","filter","value","undefined","length","fromEntries"],"mappings":"AAIA,6FAA6F,GAC7F,OAAO,SAASA,kBAAoCC,KAAQ;IAC1D,MAAMC,UAAUC,OAAOD,OAAO,CAACD;IAC/B,MAAMG,UAAUF,QAAQG,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAKA,UAAUC;IAExD,OAAOH,QAAQI,MAAM,KAAKN,QAAQM,MAAM,GAAGP,QAASE,OAAOM,WAAW,CAACL;AACzE"}
|
|
@@ -8,30 +8,40 @@ Object.defineProperty(exports, "drizzleConnectionHelpers", {
|
|
|
8
8
|
return drizzleConnectionHelpers;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _core = require("@pothos/core");
|
|
12
|
+
const _adapter = require("./utils/adapter.js");
|
|
13
|
+
const _awaitselections = require("./utils/await-selections.js");
|
|
11
14
|
const _config = require("./utils/config.js");
|
|
12
15
|
const _cursors = require("./utils/cursors.js");
|
|
13
16
|
const _mapquery = require("./utils/map-query.js");
|
|
14
17
|
const _refs = require("./utils/refs.js");
|
|
15
18
|
const _selections = require("./utils/selections.js");
|
|
16
19
|
var _builder_options_drizzle, _builder_options_drizzle1;
|
|
17
|
-
function drizzleConnectionHelpers(builder, refOrType, { select, resolveNode, query, args: createArgs, maxSize = (_builder_options_drizzle = builder.options.drizzle) === null || _builder_options_drizzle === void 0 ? void 0 : _builder_options_drizzle.maxConnectionSize, defaultSize = (_builder_options_drizzle1 = builder.options.drizzle) === null || _builder_options_drizzle1 === void 0 ? void 0 : _builder_options_drizzle1.defaultConnectionSize }) {
|
|
20
|
+
function drizzleConnectionHelpers(builder, refOrType, { select, resolveNode, query, args: createArgs, maxSize = (_builder_options_drizzle = builder.options.drizzle) === null || _builder_options_drizzle === void 0 ? void 0 : _builder_options_drizzle.maxConnectionSize, defaultSize = (_builder_options_drizzle1 = builder.options.drizzle) === null || _builder_options_drizzle1 === void 0 ? void 0 : _builder_options_drizzle1.defaultConnectionSize } = {}) {
|
|
18
21
|
const config = (0, _config.getSchemaConfig)(builder);
|
|
22
|
+
const adapter = (0, _adapter.drizzleAdapter)(config);
|
|
19
23
|
const tableName = typeof refOrType === 'string' ? refOrType : refOrType.tableName;
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
/** The user's `query`, a promise when its callback is async, which the caller awaits. */ const baseQueryFor = (args, ctx)=>(0, _core.completeValue)(typeof query === 'function' ? query(args, ctx) : query, orEmpty);
|
|
25
|
+
// Built once per helper, so a synchronous `resolve` allocates nothing beyond the connection.
|
|
26
|
+
const resolveList = (baseQuery, list, args, ctx, parent)=>{
|
|
27
|
+
const { select, cursorFields } = getQueryArgs(args, ctx, baseQuery);
|
|
22
28
|
const formatCursor = (0, _cursors.getCursorFormatter)(cursorFields, config);
|
|
23
29
|
return (0, _cursors.wrapConnectionResult)(list, args, select.limit, formatCursor, resolveNode !== null && resolveNode !== void 0 ? resolveNode : (edge)=>edge, parent);
|
|
30
|
+
};
|
|
31
|
+
function resolve(list, args, ctx, parent) {
|
|
32
|
+
const baseQuery = baseQueryFor(args, ctx);
|
|
33
|
+
return (0, _core.isThenable)(baseQuery) ? baseQuery.then((resolved)=>resolveList(resolved, list, args, ctx, parent)) : resolveList(baseQuery, list, args, ctx, parent);
|
|
24
34
|
}
|
|
25
|
-
const getQueryArgs = (args, ctx)=>{
|
|
26
|
-
var _ref
|
|
27
|
-
const { limit, orderBy, where, ...fieldQuery } =
|
|
35
|
+
const getQueryArgs = (args, ctx, baseQuery)=>{
|
|
36
|
+
var _ref;
|
|
37
|
+
const { limit, orderBy, where, ...fieldQuery } = baseQuery;
|
|
28
38
|
const table = config.relations[tableName];
|
|
29
39
|
const { cursorFields, columns, ...connectionQuery } = (0, _cursors.drizzleCursorConnectionQuery)({
|
|
30
40
|
ctx,
|
|
31
41
|
maxSize,
|
|
32
42
|
defaultSize: typeof defaultSize === 'function' ? defaultSize(args, ctx) : defaultSize,
|
|
33
43
|
args,
|
|
34
|
-
orderBy: (
|
|
44
|
+
orderBy: (_ref = typeof orderBy === 'function' ? orderBy(table) : orderBy) !== null && _ref !== void 0 ? _ref : (0, _config.getSchemaConfig)(builder).getPrimaryKey(tableName),
|
|
35
45
|
extras: fieldQuery.extras,
|
|
36
46
|
where,
|
|
37
47
|
config,
|
|
@@ -50,16 +60,20 @@ function drizzleConnectionHelpers(builder, refOrType, { select, resolveNode, que
|
|
|
50
60
|
cursorFields
|
|
51
61
|
};
|
|
52
62
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The connection's query, built from the helper's own `select` and `query` and the selection
|
|
65
|
+
* beneath the field. Synchronous unless `awaitSelections` says otherwise: an async `select` or
|
|
66
|
+
* `query`, or an async selection beneath the connection, throws rather than returning a promise
|
|
67
|
+
* the declared type denies.
|
|
68
|
+
*/ function getQuery(args, ctx, nestedSelectionOrInfo, options) {
|
|
56
69
|
const nestedSelection = typeof nestedSelectionOrInfo === 'function' ? nestedSelectionOrInfo : (select, path)=>(0, _mapquery.queryFromInfo)({
|
|
57
70
|
info: nestedSelectionOrInfo,
|
|
58
71
|
context: ctx,
|
|
59
72
|
config,
|
|
60
|
-
select,
|
|
73
|
+
select: select,
|
|
61
74
|
path
|
|
62
75
|
});
|
|
76
|
+
// Both callbacks start now; the query waits for whichever of them is async.
|
|
63
77
|
const nestedSelect = select ? select((sel)=>nestedSelection(sel, [
|
|
64
78
|
'edges',
|
|
65
79
|
'node'
|
|
@@ -67,20 +81,39 @@ function drizzleConnectionHelpers(builder, refOrType, { select, resolveNode, que
|
|
|
67
81
|
'edges',
|
|
68
82
|
'node'
|
|
69
83
|
]);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
let baseQuery;
|
|
85
|
+
try {
|
|
86
|
+
baseQuery = baseQueryFor(args, ctx);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
// The selection has already started. Preserve the query error while handling any
|
|
89
|
+
// later rejection from the selection that this invocation can no longer consume.
|
|
90
|
+
if ((0, _core.isThenable)(nestedSelect)) {
|
|
91
|
+
nestedSelect.then(()=>{}, ()=>{});
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
const built = (0, _core.isThenable)(nestedSelect) || (0, _core.isThenable)(baseQuery) ? Promise.all([
|
|
96
|
+
nestedSelect,
|
|
97
|
+
baseQuery
|
|
98
|
+
]).then(([nested, base])=>buildQuery(nested, base, args, ctx)) : buildQuery(nestedSelect, baseQuery, args, ctx);
|
|
99
|
+
return (0, _awaitselections.checkAwaitSelections)(built, options === null || options === void 0 ? void 0 : options.awaitSelections, 'getQuery', `the ${String(tableName)} connection`);
|
|
100
|
+
}
|
|
101
|
+
// Built once per helper, so a synchronous `getQuery` allocates nothing beyond the query.
|
|
102
|
+
function buildQuery(nestedSelect, baseQuery, args, ctx) {
|
|
103
|
+
const node = adapter.createNode(config.relations[tableName]);
|
|
104
|
+
adapter.mergeQuery(node, getQueryArgs(args, ctx, baseQuery).select);
|
|
73
105
|
if (typeof nestedSelect === 'object' && nestedSelect) {
|
|
74
|
-
|
|
106
|
+
adapter.mergeQuery(node, nestedSelect);
|
|
75
107
|
}
|
|
76
|
-
const baseQuery = typeof query === 'function' ? query(args, ctx) : query !== null && query !== void 0 ? query : {};
|
|
77
|
-
const queryResult = (0, _selections.selectionToQuery)(config, selectState);
|
|
78
108
|
return (0, _selections.omitUndefinedKeys)({
|
|
79
109
|
...baseQuery,
|
|
80
|
-
...
|
|
110
|
+
...adapter.toQuery(node)
|
|
81
111
|
});
|
|
82
112
|
}
|
|
83
113
|
const getArgs = ()=>createArgs ? builder.args(createArgs) : {};
|
|
114
|
+
function orEmpty(baseQuery) {
|
|
115
|
+
return baseQuery !== null && baseQuery !== void 0 ? baseQuery : {};
|
|
116
|
+
}
|
|
84
117
|
return {
|
|
85
118
|
ref: typeof refOrType === 'string' ? (0, _refs.getRefFromModel)(refOrType, builder) : refOrType,
|
|
86
119
|
resolve,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/connection-helpers.ts"],"names":["drizzleConnectionHelpers","builder","refOrType","select","resolveNode","query","args","createArgs","maxSize","options","drizzle","maxConnectionSize","defaultSize","defaultConnectionSize","config","getSchemaConfig","
|
|
1
|
+
{"version":3,"sources":["../src/connection-helpers.ts"],"names":["drizzleConnectionHelpers","builder","refOrType","select","resolveNode","query","args","createArgs","maxSize","options","drizzle","maxConnectionSize","defaultSize","defaultConnectionSize","config","getSchemaConfig","adapter","drizzleAdapter","tableName","baseQueryFor","ctx","completeValue","orEmpty","resolveList","baseQuery","list","parent","cursorFields","getQueryArgs","formatCursor","getCursorFormatter","wrapConnectionResult","limit","edge","resolve","isThenable","then","resolved","orderBy","where","fieldQuery","table","relations","columns","connectionQuery","drizzleCursorConnectionQuery","getPrimaryKey","extras","Math","abs","getQuery","nestedSelectionOrInfo","nestedSelection","path","queryFromInfo","info","context","nestedSelect","sel","error","built","Promise","all","nested","base","buildQuery","checkAwaitSelections","awaitSelections","String","node","createNode","mergeQuery","omitUndefinedKeys","toQuery","getArgs","ref","getRefFromModel"],"mappings":";;;;+BAiCgBA;;;eAAAA;;;sBAzBT;yBAYwB;iCACM;wBACL;yBAMzB;0BACuB;sBACE;4BACqB;IAiCvCC,0BACIA;AAhCX,SAASD,yBAwBdC,OAA+C,EAC/CC,SAAe,EACf,EACEC,MAAM,EACNC,WAAW,EACXC,KAAK,EACLC,MAAMC,UAAU,EAChBC,WAAUP,2BAAAA,QAAQQ,OAAO,CAACC,OAAO,cAAvBT,+CAAAA,yBAAyBU,iBAAiB,EACpDC,eAAcX,4BAAAA,QAAQQ,OAAO,CAACC,OAAO,cAAvBT,gDAAAA,0BAAyBY,qBAAqB,EA2B7D,GAAG,CAAC,CAAC;IAEN,MAAMC,SAASC,IAAAA,uBAAe,EAACd;IAC/B,MAAMe,UAAUC,IAAAA,uBAAc,EAACH;IAC/B,MAAMI,YACJ,OAAOhB,cAAc,WACjBA,YACA,AAACA,UACEgB,SAAS;IAUlB,uFAAuF,GACvF,MAAMC,eAAe,CACnBb,MACAc,MAEAC,IAAAA,mBAAa,EACV,OAA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