@pothos/plugin-drizzle 0.8.0 → 0.9.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 +98 -0
- package/TODO.md +25 -4
- package/dts/connection-helpers.d.ts +32 -0
- package/dts/connection-helpers.d.ts.map +1 -0
- package/dts/drizzle-field-builder.d.ts +18 -53
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +22 -41
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +4 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +3 -2
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +3 -2
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts +1 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts +2 -2
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/types.d.ts +61 -41
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/config.d.ts +4 -3
- package/dts/utils/config.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +13 -7
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/drizzle-graphql.d.ts +0 -17
- package/dts/utils/drizzle-graphql.d.ts.map +1 -1
- package/dts/utils/map-query.d.ts.map +1 -1
- package/dts/utils/selections.d.ts +5 -5
- package/dts/utils/selections.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +34 -0
- package/esm/connection-helpers.d.ts.map +1 -0
- package/esm/connection-helpers.js +74 -0
- package/esm/connection-helpers.js.map +1 -0
- package/esm/drizzle-field-builder.d.ts +18 -73
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +25 -14
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/field-builder.js +2 -3
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts +35 -60
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts +4 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +70 -61
- package/esm/index.js.map +1 -1
- package/esm/interface-ref.d.ts +3 -2
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +3 -2
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +18 -10
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +1 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/object-ref.d.ts +2 -2
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/schema-builder.js +111 -65
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +61 -41
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/config.d.ts +4 -3
- package/esm/utils/config.d.ts.map +1 -1
- package/esm/utils/config.js +32 -15
- package/esm/utils/config.js.map +1 -1
- package/esm/utils/cursors.d.ts +13 -7
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +137 -63
- package/esm/utils/cursors.js.map +1 -1
- package/esm/utils/drizzle-graphql.d.ts +0 -17
- package/esm/utils/drizzle-graphql.d.ts.map +1 -1
- package/esm/utils/drizzle-graphql.js +230 -198
- package/esm/utils/drizzle-graphql.js.map +1 -1
- package/esm/utils/map-query.d.ts.map +1 -1
- package/esm/utils/map-query.js +9 -5
- package/esm/utils/map-query.js.map +1 -1
- package/esm/utils/selections.d.ts +5 -5
- package/esm/utils/selections.d.ts.map +1 -1
- package/esm/utils/selections.js +19 -18
- package/esm/utils/selections.js.map +1 -1
- package/lib/connection-helpers.js +85 -0
- package/lib/connection-helpers.js.map +1 -0
- package/lib/drizzle-field-builder.js +24 -13
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/field-builder.js +2 -3
- package/lib/field-builder.js.map +1 -1
- package/lib/index.js +75 -60
- package/lib/index.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js +18 -10
- package/lib/model-loader.js.map +1 -1
- package/lib/schema-builder.js +111 -65
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/config.js +31 -14
- package/lib/utils/config.js.map +1 -1
- package/lib/utils/cursors.js +135 -63
- package/lib/utils/cursors.js.map +1 -1
- package/lib/utils/drizzle-graphql.js +230 -221
- package/lib/utils/drizzle-graphql.js.map +1 -1
- package/lib/utils/map-query.js +9 -5
- package/lib/utils/map-query.js.map +1 -1
- package/lib/utils/selections.js +18 -17
- package/lib/utils/selections.js.map +1 -1
- package/package.json +14 -14
- package/src/connection-helpers.ts +184 -0
- package/src/drizzle-field-builder.ts +30 -26
- package/src/field-builder.ts +4 -7
- package/src/global-types.ts +112 -119
- package/src/index.ts +90 -68
- package/src/interface-ref.ts +7 -3
- package/src/model-loader.ts +33 -17
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +2 -2
- package/src/schema-builder.ts +114 -111
- package/src/types.ts +95 -62
- package/src/utils/config.ts +39 -30
- package/src/utils/cursors.ts +134 -101
- package/src/utils/drizzle-graphql.ts +273 -274
- package/src/utils/map-query.ts +19 -7
- package/src/utils/selections.ts +34 -28
package/src/utils/selections.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { PothosValidationError } from '@pothos/core';
|
|
2
2
|
import {
|
|
3
3
|
type DBQueryConfig,
|
|
4
|
-
type
|
|
4
|
+
type SQLOperator,
|
|
5
|
+
type SQLWrapper,
|
|
6
|
+
type Table,
|
|
5
7
|
type TableRelationalConfig,
|
|
6
|
-
|
|
8
|
+
getTableUniqueName,
|
|
7
9
|
} from 'drizzle-orm';
|
|
8
10
|
import type { PothosDrizzleSchemaConfig } from './config';
|
|
9
11
|
import { deepEqual } from './deep-equal';
|
|
@@ -15,14 +17,14 @@ export interface SelectionState {
|
|
|
15
17
|
allColumns: boolean;
|
|
16
18
|
columns: Set<string>;
|
|
17
19
|
with: Map<string, SelectionState>;
|
|
18
|
-
extras: Map<string,
|
|
20
|
+
extras: Map<string, NonNullable<SelectionMap['extras']>[string]>;
|
|
19
21
|
mappings: LoaderMappings;
|
|
20
22
|
parent?: SelectionState;
|
|
21
23
|
depth: number;
|
|
22
24
|
skipDeferredFragments: boolean;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export type SelectionMap = DBQueryConfig<'one'
|
|
27
|
+
export type SelectionMap = DBQueryConfig<'one'>;
|
|
26
28
|
|
|
27
29
|
export function selectionCompatible(
|
|
28
30
|
state: SelectionState,
|
|
@@ -48,15 +50,11 @@ export function selectionCompatible(
|
|
|
48
50
|
return false;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const resolvedExtras =
|
|
52
|
-
typeof extras === 'function' ? extras(state.table.columns, getOperators()) : extras;
|
|
53
|
-
|
|
54
53
|
if (
|
|
55
|
-
|
|
56
|
-
Object.entries(
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
return sql && (sql.sql !== value.sql || sql.fieldAlias !== value.fieldAlias);
|
|
54
|
+
extras &&
|
|
55
|
+
Object.entries(extras).some(([key, value]) => {
|
|
56
|
+
const existing = state.extras.get(key);
|
|
57
|
+
return existing && existing !== value;
|
|
60
58
|
})
|
|
61
59
|
) {
|
|
62
60
|
return false;
|
|
@@ -123,8 +121,14 @@ export function createState(
|
|
|
123
121
|
export function mergeSelection(
|
|
124
122
|
config: PothosDrizzleSchemaConfig,
|
|
125
123
|
state: SelectionState,
|
|
126
|
-
|
|
124
|
+
selection: SelectionMap | boolean,
|
|
127
125
|
) {
|
|
126
|
+
const {
|
|
127
|
+
with: withSelection,
|
|
128
|
+
extras,
|
|
129
|
+
columns,
|
|
130
|
+
...query
|
|
131
|
+
} = typeof selection === 'boolean' ? {} : selection;
|
|
128
132
|
if (withSelection) {
|
|
129
133
|
for (const [key, value] of Object.entries(withSelection)) {
|
|
130
134
|
const relation = state.table.relations[key];
|
|
@@ -133,7 +137,9 @@ export function mergeSelection(
|
|
|
133
137
|
throw new PothosValidationError(`Relation ${key} does not exist on ${state.table.dbName}`);
|
|
134
138
|
}
|
|
135
139
|
|
|
136
|
-
|
|
140
|
+
const tableUniqueName = getTableUniqueName(relation.targetTable as Table);
|
|
141
|
+
const tableName = config.relations.tableNamesMap[tableUniqueName];
|
|
142
|
+
merge(config.relations.tablesConfig[tableName], key, value as SelectionMap | boolean);
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
145
|
|
|
@@ -141,11 +147,8 @@ export function mergeSelection(
|
|
|
141
147
|
state.query = query;
|
|
142
148
|
}
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (resolvedExtras) {
|
|
148
|
-
for (const [key, value] of Object.entries(resolvedExtras)) {
|
|
150
|
+
if (extras) {
|
|
151
|
+
for (const [key, value] of Object.entries(extras)) {
|
|
149
152
|
state.extras.set(key, value);
|
|
150
153
|
}
|
|
151
154
|
}
|
|
@@ -158,7 +161,7 @@ export function mergeSelection(
|
|
|
158
161
|
for (const key of Object.keys(columns)) {
|
|
159
162
|
state.columns.add(key);
|
|
160
163
|
}
|
|
161
|
-
} else {
|
|
164
|
+
} else if (selection === true) {
|
|
162
165
|
state.allColumns = true;
|
|
163
166
|
}
|
|
164
167
|
|
|
@@ -167,19 +170,20 @@ export function mergeSelection(
|
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
169
172
|
|
|
170
|
-
const selection = value === true ? {} : value;
|
|
171
|
-
|
|
172
173
|
if (state.with.has(key)) {
|
|
173
|
-
mergeSelection(config, state.with.get(key)!,
|
|
174
|
+
mergeSelection(config, state.with.get(key)!, value);
|
|
174
175
|
} else {
|
|
175
176
|
const relatedState = createState(table, state.skipDeferredFragments, state);
|
|
176
|
-
mergeSelection(config, relatedState,
|
|
177
|
+
mergeSelection(config, relatedState, value);
|
|
177
178
|
state.with.set(key, relatedState);
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
export function selectionToQuery(
|
|
183
|
+
export function selectionToQuery(
|
|
184
|
+
config: PothosDrizzleSchemaConfig,
|
|
185
|
+
state: SelectionState,
|
|
186
|
+
): SelectionMap {
|
|
183
187
|
const query: SelectionMap & { extras: Record<string, unknown> } = {
|
|
184
188
|
...state.query,
|
|
185
189
|
with: {},
|
|
@@ -195,8 +199,10 @@ export function selectionToQuery(state: SelectionState): SelectionMap {
|
|
|
195
199
|
for (const key of state.columns) {
|
|
196
200
|
query.columns![key] = true;
|
|
197
201
|
}
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
|
|
203
|
+
for (const column of config.getPrimaryKey(state.table.tsName)) {
|
|
204
|
+
const tsName = config.columnToTsName(column);
|
|
205
|
+
query.columns![tsName] = true;
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
208
|
|
|
@@ -205,7 +211,7 @@ export function selectionToQuery(state: SelectionState): SelectionMap {
|
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
state.with.forEach((sel, relation) => {
|
|
208
|
-
query.with![relation] = selectionToQuery(sel);
|
|
214
|
+
query.with![relation] = selectionToQuery(config, sel);
|
|
209
215
|
});
|
|
210
216
|
|
|
211
217
|
return query;
|