@pothos/plugin-drizzle 0.8.1 → 0.10.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/TODO.md +25 -4
  3. package/dts/connection-helpers.d.ts +34 -0
  4. package/dts/connection-helpers.d.ts.map +1 -0
  5. package/dts/drizzle-field-builder.d.ts +18 -53
  6. package/dts/drizzle-field-builder.d.ts.map +1 -1
  7. package/dts/global-types.d.ts +22 -41
  8. package/dts/global-types.d.ts.map +1 -1
  9. package/dts/index.d.ts +5 -2
  10. package/dts/index.d.ts.map +1 -1
  11. package/dts/interface-ref.d.ts +3 -2
  12. package/dts/interface-ref.d.ts.map +1 -1
  13. package/dts/model-loader.d.ts +3 -2
  14. package/dts/model-loader.d.ts.map +1 -1
  15. package/dts/node-ref.d.ts +1 -1
  16. package/dts/node-ref.d.ts.map +1 -1
  17. package/dts/object-ref.d.ts +2 -2
  18. package/dts/object-ref.d.ts.map +1 -1
  19. package/dts/types.d.ts +61 -41
  20. package/dts/types.d.ts.map +1 -1
  21. package/dts/utils/config.d.ts +4 -3
  22. package/dts/utils/config.d.ts.map +1 -1
  23. package/dts/utils/cursors.d.ts +13 -7
  24. package/dts/utils/cursors.d.ts.map +1 -1
  25. package/dts/utils/drizzle-graphql.d.ts +0 -17
  26. package/dts/utils/drizzle-graphql.d.ts.map +1 -1
  27. package/dts/utils/map-query.d.ts.map +1 -1
  28. package/dts/utils/selections.d.ts +5 -5
  29. package/dts/utils/selections.d.ts.map +1 -1
  30. package/esm/connection-helpers.d.ts +36 -0
  31. package/esm/connection-helpers.d.ts.map +1 -0
  32. package/esm/connection-helpers.js +82 -0
  33. package/esm/connection-helpers.js.map +1 -0
  34. package/esm/drizzle-field-builder.d.ts +18 -73
  35. package/esm/drizzle-field-builder.d.ts.map +1 -1
  36. package/esm/drizzle-field-builder.js +25 -14
  37. package/esm/drizzle-field-builder.js.map +1 -1
  38. package/esm/field-builder.js +2 -3
  39. package/esm/field-builder.js.map +1 -1
  40. package/esm/global-types.d.ts +35 -60
  41. package/esm/global-types.d.ts.map +1 -1
  42. package/esm/global-types.js.map +1 -1
  43. package/esm/index.d.ts +5 -2
  44. package/esm/index.d.ts.map +1 -1
  45. package/esm/index.js +71 -61
  46. package/esm/index.js.map +1 -1
  47. package/esm/interface-ref.d.ts +3 -2
  48. package/esm/interface-ref.d.ts.map +1 -1
  49. package/esm/interface-ref.js.map +1 -1
  50. package/esm/model-loader.d.ts +3 -2
  51. package/esm/model-loader.d.ts.map +1 -1
  52. package/esm/model-loader.js +17 -10
  53. package/esm/model-loader.js.map +1 -1
  54. package/esm/node-ref.d.ts +1 -1
  55. package/esm/node-ref.d.ts.map +1 -1
  56. package/esm/object-ref.d.ts +2 -2
  57. package/esm/object-ref.d.ts.map +1 -1
  58. package/esm/schema-builder.js +113 -67
  59. package/esm/schema-builder.js.map +1 -1
  60. package/esm/types.d.ts +61 -41
  61. package/esm/types.d.ts.map +1 -1
  62. package/esm/types.js.map +1 -1
  63. package/esm/utils/config.d.ts +4 -3
  64. package/esm/utils/config.d.ts.map +1 -1
  65. package/esm/utils/config.js +32 -15
  66. package/esm/utils/config.js.map +1 -1
  67. package/esm/utils/cursors.d.ts +13 -7
  68. package/esm/utils/cursors.d.ts.map +1 -1
  69. package/esm/utils/cursors.js +137 -63
  70. package/esm/utils/cursors.js.map +1 -1
  71. package/esm/utils/drizzle-graphql.d.ts +0 -17
  72. package/esm/utils/drizzle-graphql.d.ts.map +1 -1
  73. package/esm/utils/drizzle-graphql.js +230 -198
  74. package/esm/utils/drizzle-graphql.js.map +1 -1
  75. package/esm/utils/map-query.d.ts.map +1 -1
  76. package/esm/utils/map-query.js +10 -6
  77. package/esm/utils/map-query.js.map +1 -1
  78. package/esm/utils/selections.d.ts +5 -5
  79. package/esm/utils/selections.d.ts.map +1 -1
  80. package/esm/utils/selections.js +19 -18
  81. package/esm/utils/selections.js.map +1 -1
  82. package/lib/connection-helpers.js +93 -0
  83. package/lib/connection-helpers.js.map +1 -0
  84. package/lib/drizzle-field-builder.js +24 -13
  85. package/lib/drizzle-field-builder.js.map +1 -1
  86. package/lib/field-builder.js +2 -3
  87. package/lib/field-builder.js.map +1 -1
  88. package/lib/index.js +79 -60
  89. package/lib/index.js.map +1 -1
  90. package/lib/interface-ref.js.map +1 -1
  91. package/lib/model-loader.js +17 -10
  92. package/lib/model-loader.js.map +1 -1
  93. package/lib/schema-builder.js +113 -67
  94. package/lib/schema-builder.js.map +1 -1
  95. package/lib/types.js.map +1 -1
  96. package/lib/utils/config.js +31 -14
  97. package/lib/utils/config.js.map +1 -1
  98. package/lib/utils/cursors.js +135 -63
  99. package/lib/utils/cursors.js.map +1 -1
  100. package/lib/utils/drizzle-graphql.js +230 -221
  101. package/lib/utils/drizzle-graphql.js.map +1 -1
  102. package/lib/utils/map-query.js +10 -6
  103. package/lib/utils/map-query.js.map +1 -1
  104. package/lib/utils/selections.js +18 -17
  105. package/lib/utils/selections.js.map +1 -1
  106. package/package.json +14 -14
  107. package/src/connection-helpers.ts +206 -0
  108. package/src/drizzle-field-builder.ts +30 -26
  109. package/src/field-builder.ts +4 -7
  110. package/src/global-types.ts +112 -119
  111. package/src/index.ts +91 -70
  112. package/src/interface-ref.ts +7 -3
  113. package/src/model-loader.ts +32 -17
  114. package/src/node-ref.ts +1 -1
  115. package/src/object-ref.ts +2 -2
  116. package/src/schema-builder.ts +116 -113
  117. package/src/types.ts +95 -62
  118. package/src/utils/config.ts +39 -30
  119. package/src/utils/cursors.ts +134 -101
  120. package/src/utils/drizzle-graphql.ts +273 -274
  121. package/src/utils/map-query.ts +20 -8
  122. package/src/utils/selections.ts +34 -28
@@ -1,274 +1,273 @@
1
- import {
2
- type Column,
3
- type SQL,
4
- Table,
5
- type TableRelationalConfig,
6
- asc,
7
- desc,
8
- getOperators,
9
- } from 'drizzle-orm';
10
- import { GraphQLError } from 'graphql';
11
-
12
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
13
- export const remapFromGraphQLCore = (value: any, column: Column, columnName: string) => {
14
- switch (column.dataType) {
15
- case 'date': {
16
- const formatted = new Date(value);
17
- if (Number.isNaN(formatted.getTime())) {
18
- throw new GraphQLError(`Field '${columnName}' is not a valid date!`);
19
- }
20
-
21
- return formatted;
22
- }
23
-
24
- case 'buffer': {
25
- if (!Array.isArray(value)) {
26
- throw new GraphQLError(`Field '${columnName}' is not an array!`);
27
- }
28
-
29
- return Buffer.from(value);
30
- }
31
-
32
- case 'json': {
33
- if (column.columnType === 'PgGeometryObject') {
34
- return value;
35
- }
36
-
37
- try {
38
- return JSON.parse(value);
39
- } catch (e) {
40
- throw new GraphQLError(
41
- `Invalid JSON in field '${columnName}':\n${e instanceof Error ? e.message : 'Unknown error'}`,
42
- );
43
- }
44
- }
45
-
46
- case 'array': {
47
- if (!Array.isArray(value)) {
48
- throw new GraphQLError(`Field '${columnName}' is not an array!`);
49
- }
50
-
51
- if (column.columnType === 'PgGeometry' && value.length !== 2) {
52
- throw new GraphQLError(
53
- `Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`,
54
- );
55
- }
56
-
57
- return value;
58
- }
59
-
60
- case 'bigint': {
61
- try {
62
- return BigInt(value);
63
- } catch (_error) {
64
- throw new GraphQLError(`Field '${columnName}' is not a BigInt!`);
65
- }
66
- }
67
-
68
- default: {
69
- return value;
70
- }
71
- }
72
- };
73
-
74
- export const remapFromGraphQLSingleInput = (
75
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
76
- queryInput: Record<string, any>,
77
- table: TableRelationalConfig,
78
- ) => {
79
- for (const [key, value] of Object.entries(queryInput)) {
80
- if (value === undefined) {
81
- delete queryInput[key];
82
- } else {
83
- const column = table.columns[key];
84
- if (!column) {
85
- throw new GraphQLError(`Unknown column: ${key}`);
86
- }
87
-
88
- if (value === null && column.notNull) {
89
- delete queryInput[key];
90
- continue;
91
- }
92
-
93
- queryInput[key] = remapFromGraphQLCore(value, column, key);
94
- }
95
- }
96
-
97
- return queryInput;
98
- };
99
-
100
- export const remapFromGraphQLArrayInput = (
101
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
102
- queryInput: Record<string, any>[],
103
- table: TableRelationalConfig,
104
- ) => {
105
- for (const entry of queryInput) {
106
- remapFromGraphQLSingleInput(entry, table);
107
- }
108
-
109
- return queryInput;
110
- };
111
-
112
- export type OrderByArgs<TTable extends TableRelationalConfig> = {
113
- [Key in keyof TTable['columns']]?: {
114
- direction: 'asc' | 'desc';
115
- priority: number;
116
- };
117
- };
118
-
119
- export const extractOrderBy = <
120
- TTable extends TableRelationalConfig,
121
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
122
- TArgs extends OrderByArgs<any> = OrderByArgs<TTable>,
123
- >(
124
- table: TTable,
125
- orderArgs: TArgs,
126
- ): SQL[] => {
127
- const res = [] as SQL[];
128
-
129
- for (const [column, config] of Object.entries(orderArgs).sort(
130
- (a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0),
131
- )) {
132
- if (!config) {
133
- continue;
134
- }
135
- const { direction } = config;
136
-
137
- res.push(direction === 'asc' ? asc(table.columns[column]!) : desc(table.columns[column]!));
138
- }
139
-
140
- return res;
141
- };
142
-
143
- const ops = getOperators();
144
-
145
- export const extractFiltersColumn = <TColumn extends Column>(
146
- column: TColumn,
147
- columnName: string,
148
- operators: Record<string, unknown> & { OR?: Record<string, unknown>[] },
149
- ): SQL | undefined => {
150
- if (!operators.OR?.length) {
151
- // biome-ignore lint/performance/noDelete: <explanation>
152
- delete operators.OR;
153
- }
154
-
155
- const entries = Object.entries(operators);
156
-
157
- if (operators.OR) {
158
- if (entries.length > 1) {
159
- throw new GraphQLError(
160
- `WHERE ${columnName}: Cannot specify both fields and 'OR' in column operators!`,
161
- );
162
- }
163
-
164
- const variants = [] as SQL[];
165
-
166
- for (const variant of operators.OR) {
167
- const extracted = extractFiltersColumn(column, columnName, variant);
168
-
169
- // biome-ignore lint/style/useBlockStatements: <explanation>
170
- if (extracted) variants.push(extracted);
171
- }
172
-
173
- return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
174
- }
175
-
176
- const variants = [] as SQL[];
177
- for (const [operatorName, operatorValue] of entries) {
178
- // biome-ignore lint/style/useBlockStatements: <explanation>
179
- if (operatorValue === null || operatorValue === false) continue;
180
-
181
- switch (operatorName) {
182
- case 'eq':
183
- case 'ne':
184
- case 'gt':
185
- case 'gte':
186
- case 'lt':
187
- case 'lte': {
188
- const singleValue = remapFromGraphQLCore(operatorValue, column, columnName);
189
- variants.push(ops[operatorName](column, singleValue));
190
-
191
- break;
192
- }
193
- case 'like':
194
- case 'notLike':
195
- case 'ilike':
196
- case 'notIlike':
197
- variants.push(ops[operatorName](column, operatorValue as string));
198
- break;
199
- case 'inArray':
200
- case 'notInArray': {
201
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
202
- if (!(operatorValue as any[]).length) {
203
- throw new GraphQLError(
204
- `WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`,
205
- );
206
- }
207
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
208
- const arrayValue = (operatorValue as any[]).map((val) =>
209
- remapFromGraphQLCore(val, column, columnName),
210
- );
211
-
212
- variants.push(ops[operatorName](column, arrayValue));
213
- break;
214
- }
215
- case 'isNull':
216
- case 'isNotNull':
217
- variants.push(ops[operatorName](column));
218
- break;
219
- default:
220
- throw new GraphQLError(`Unknown operator: ${operatorName}`);
221
- }
222
- }
223
-
224
- return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
225
- };
226
-
227
- export const extractFilters = <TTable extends TableRelationalConfig>(
228
- table: TTable,
229
- tableName: string,
230
- filters: Record<string, unknown> & {
231
- OR?: Record<string, unknown>[];
232
- },
233
- ): SQL | undefined => {
234
- if (!filters.OR?.length) {
235
- // biome-ignore lint/performance/noDelete: <explanation>
236
- delete filters.OR;
237
- }
238
-
239
- const entries = Object.entries(filters);
240
- if (!entries.length) {
241
- return;
242
- }
243
-
244
- if (filters.OR) {
245
- if (entries.length > 1) {
246
- throw new GraphQLError(
247
- `WHERE ${tableName}: Cannot specify both fields and 'OR' in table filters!`,
248
- );
249
- }
250
-
251
- const variants = [] as SQL[];
252
-
253
- for (const variant of filters.OR) {
254
- const extracted = extractFilters(table, tableName, variant);
255
- if (extracted) {
256
- variants.push(extracted);
257
- }
258
- }
259
-
260
- return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
261
- }
262
-
263
- const variants = [] as SQL[];
264
- for (const [columnName, operators] of entries) {
265
- if (operators === null) {
266
- continue;
267
- }
268
-
269
- const column = table.columns[columnName]!;
270
- variants.push(extractFiltersColumn(column, columnName, operators as Record<string, unknown>)!);
271
- }
272
-
273
- return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
274
- };
1
+ // import {
2
+ // type Column,
3
+ // type SQL,
4
+ // type TableRelationalConfig,
5
+ // asc,
6
+ // desc,
7
+ // operators as ops,
8
+ // } from 'drizzle-orm';
9
+ // import { GraphQLError } from 'graphql';
10
+
11
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
12
+ // export const remapFromGraphQLCore = (value: any, column: Column, columnName: string) => {
13
+ // switch (column.dataType) {
14
+ // case 'date': {
15
+ // const formatted = new Date(value);
16
+ // if (Number.isNaN(formatted.getTime())) {
17
+ // throw new GraphQLError(`Field '${columnName}' is not a valid date!`);
18
+ // }
19
+
20
+ // return formatted;
21
+ // }
22
+
23
+ // case 'buffer': {
24
+ // if (!Array.isArray(value)) {
25
+ // throw new GraphQLError(`Field '${columnName}' is not an array!`);
26
+ // }
27
+
28
+ // return Buffer.from(value);
29
+ // }
30
+
31
+ // case 'json': {
32
+ // if (column.columnType === 'PgGeometryObject') {
33
+ // return value;
34
+ // }
35
+
36
+ // try {
37
+ // return JSON.parse(value);
38
+ // } catch (e) {
39
+ // throw new GraphQLError(
40
+ // `Invalid JSON in field '${columnName}':\n${e instanceof Error ? e.message : 'Unknown error'}`,
41
+ // );
42
+ // }
43
+ // }
44
+
45
+ // case 'array': {
46
+ // if (!Array.isArray(value)) {
47
+ // throw new GraphQLError(`Field '${columnName}' is not an array!`);
48
+ // }
49
+
50
+ // if (column.columnType === 'PgGeometry' && value.length !== 2) {
51
+ // throw new GraphQLError(
52
+ // `Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`,
53
+ // );
54
+ // }
55
+
56
+ // return value;
57
+ // }
58
+
59
+ // case 'bigint': {
60
+ // try {
61
+ // return BigInt(value);
62
+ // } catch (_error) {
63
+ // throw new GraphQLError(`Field '${columnName}' is not a BigInt!`);
64
+ // }
65
+ // }
66
+
67
+ // default: {
68
+ // return value;
69
+ // }
70
+ // }
71
+ // };
72
+
73
+ // export const remapFromGraphQLSingleInput = (
74
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
75
+ // queryInput: Record<string, any>,
76
+ // table: TableRelationalConfig,
77
+ // ) => {
78
+ // for (const [key, value] of Object.entries(queryInput)) {
79
+ // if (value === undefined) {
80
+ // delete queryInput[key];
81
+ // } else {
82
+ // const column = table.columns[key];
83
+ // if (!column) {
84
+ // throw new GraphQLError(`Unknown column: ${key}`);
85
+ // }
86
+
87
+ // if (value === null && (column as Column).notNull) {
88
+ // delete queryInput[key];
89
+ // continue;
90
+ // }
91
+
92
+ // queryInput[key] = remapFromGraphQLCore(value, column as Column, key);
93
+ // }
94
+ // }
95
+
96
+ // return queryInput;
97
+ // };
98
+
99
+ // export const remapFromGraphQLArrayInput = (
100
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
101
+ // queryInput: Record<string, any>[],
102
+ // table: TableRelationalConfig,
103
+ // ) => {
104
+ // for (const entry of queryInput) {
105
+ // remapFromGraphQLSingleInput(entry, table);
106
+ // }
107
+
108
+ // return queryInput;
109
+ // };
110
+
111
+ // export type OrderByArgs<TTable extends TableRelationalConfig> = {
112
+ // [Key in keyof TTable['columns']]?: {
113
+ // direction: 'asc' | 'desc';
114
+ // priority: number;
115
+ // };
116
+ // };
117
+
118
+ // export const extractOrderBy = <
119
+ // TTable extends TableRelationalConfig,
120
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
121
+ // TArgs extends OrderByArgs<any> = OrderByArgs<TTable>,
122
+ // >(
123
+ // table: TTable,
124
+ // orderArgs: TArgs,
125
+ // ): SQL[] => {
126
+ // const res = [] as SQL[];
127
+
128
+ // for (const [column, config] of Object.entries(orderArgs).sort(
129
+ // (a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0),
130
+ // )) {
131
+ // if (!config) {
132
+ // continue;
133
+ // }
134
+ // const { direction } = config;
135
+
136
+ // res.push(direction === 'asc' ? asc(table.columns[column]!) : desc(table.columns[column]!));
137
+ // }
138
+
139
+ // return res;
140
+ // };
141
+
142
+ // export const extractFiltersColumn = <TColumn extends Column>(
143
+ // column: TColumn,
144
+ // columnName: string,
145
+ // operators: Record<string, unknown> & { OR?: Record<string, unknown>[] },
146
+ // ): SQL | undefined => {
147
+ // if (!operators.OR?.length) {
148
+ // // biome-ignore lint/performance/noDelete: <explanation>
149
+ // delete operators.OR;
150
+ // }
151
+
152
+ // const entries = Object.entries(operators);
153
+
154
+ // if (operators.OR) {
155
+ // if (entries.length > 1) {
156
+ // throw new GraphQLError(
157
+ // `WHERE ${columnName}: Cannot specify both fields and 'OR' in column operators!`,
158
+ // );
159
+ // }
160
+
161
+ // const variants = [] as SQL[];
162
+
163
+ // for (const variant of operators.OR) {
164
+ // const extracted = extractFiltersColumn(column, columnName, variant);
165
+
166
+ // // biome-ignore lint/style/useBlockStatements: <explanation>
167
+ // if (extracted) variants.push(extracted);
168
+ // }
169
+
170
+ // return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
171
+ // }
172
+
173
+ // const variants = [] as SQL[];
174
+ // for (const [operatorName, operatorValue] of entries) {
175
+ // // biome-ignore lint/style/useBlockStatements: <explanation>
176
+ // if (operatorValue === null || operatorValue === false) continue;
177
+
178
+ // switch (operatorName) {
179
+ // case 'eq':
180
+ // case 'ne':
181
+ // case 'gt':
182
+ // case 'gte':
183
+ // case 'lt':
184
+ // case 'lte': {
185
+ // const singleValue = remapFromGraphQLCore(operatorValue, column, columnName);
186
+ // variants.push(ops[operatorName](column, singleValue));
187
+
188
+ // break;
189
+ // }
190
+ // case 'like':
191
+ // case 'notLike':
192
+ // case 'ilike':
193
+ // case 'notIlike':
194
+ // variants.push(ops[operatorName](column, operatorValue as string));
195
+ // break;
196
+ // case 'inArray':
197
+ // case 'notInArray': {
198
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
199
+ // if (!(operatorValue as any[]).length) {
200
+ // throw new GraphQLError(
201
+ // `WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`,
202
+ // );
203
+ // }
204
+ // // biome-ignore lint/suspicious/noExplicitAny: <explanation>
205
+ // const arrayValue = (operatorValue as any[]).map((val) =>
206
+ // remapFromGraphQLCore(val, column, columnName),
207
+ // );
208
+
209
+ // variants.push(ops[operatorName](column, arrayValue));
210
+ // break;
211
+ // }
212
+ // case 'isNull':
213
+ // case 'isNotNull':
214
+ // variants.push(ops[operatorName](column));
215
+ // break;
216
+ // default:
217
+ // throw new GraphQLError(`Unknown operator: ${operatorName}`);
218
+ // }
219
+ // }
220
+
221
+ // return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
222
+ // };
223
+
224
+ // export const extractFilters = <TTable extends TableRelationalConfig>(
225
+ // table: TTable,
226
+ // tableName: string,
227
+ // filters: Record<string, unknown> & {
228
+ // OR?: Record<string, unknown>[];
229
+ // },
230
+ // ): SQL | undefined => {
231
+ // if (!filters.OR?.length) {
232
+ // // biome-ignore lint/performance/noDelete: <explanation>
233
+ // delete filters.OR;
234
+ // }
235
+
236
+ // const entries = Object.entries(filters);
237
+ // if (!entries.length) {
238
+ // return;
239
+ // }
240
+
241
+ // if (filters.OR) {
242
+ // if (entries.length > 1) {
243
+ // throw new GraphQLError(
244
+ // `WHERE ${tableName}: Cannot specify both fields and 'OR' in table filters!`,
245
+ // );
246
+ // }
247
+
248
+ // const variants = [] as SQL[];
249
+
250
+ // for (const variant of filters.OR) {
251
+ // const extracted = extractFilters(table, tableName, variant);
252
+ // if (extracted) {
253
+ // variants.push(extracted);
254
+ // }
255
+ // }
256
+
257
+ // return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
258
+ // }
259
+
260
+ // const variants = [] as SQL[];
261
+ // for (const [columnName, operators] of entries) {
262
+ // if (operators === null) {
263
+ // continue;
264
+ // }
265
+
266
+ // const column = table.columns[columnName]!;
267
+ // variants.push(
268
+ // extractFiltersColumn(column as Column, columnName, operators as Record<string, unknown>)!,
269
+ // );
270
+ // }
271
+
272
+ // return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
273
+ // };
@@ -54,7 +54,7 @@ function addTypeSelectionsForField(
54
54
 
55
55
  const { pothosDrizzleSelect, pothosIndirectInclude } = (type.extensions ?? {}) as {
56
56
  pothosIndirectInclude?: IndirectInclude;
57
- pothosDrizzleSelect?: DBQueryConfig<'one', false>;
57
+ pothosDrizzleSelect?: boolean | DBQueryConfig<'one'>;
58
58
  };
59
59
 
60
60
  if (
@@ -101,7 +101,7 @@ function addTypeSelectionsForField(
101
101
  }
102
102
 
103
103
  if (pothosDrizzleSelect) {
104
- mergeSelection(config, state, { ...pothosDrizzleSelect });
104
+ mergeSelection(config, state, pothosDrizzleSelect === true ? true : { ...pothosDrizzleSelect });
105
105
  }
106
106
 
107
107
  if (selection.selectionSet && (!deferred || !state.skipDeferredFragments)) {
@@ -316,7 +316,7 @@ function addFieldSelection(
316
316
 
317
317
  const fieldSelect = field.extensions?.pothosDrizzleSelect as DrizzleFieldSelection | undefined;
318
318
 
319
- let fieldSelectionMap: DBQueryConfig<'one', false> | undefined;
319
+ let fieldSelectionMap: DBQueryConfig<'one'> | undefined;
320
320
  let mappings: LoaderMappings = {};
321
321
  if (typeof fieldSelect === 'function') {
322
322
  const args = getMappedArgumentValues(field, selection, context, info) as Record<
@@ -375,7 +375,7 @@ function addFieldSelection(
375
375
  }
376
376
  addTypeSelectionsForField(config, returnType, context, info, fieldState, selection, []);
377
377
  mappings = fieldState.mappings;
378
- return selectionToQuery(fieldState);
378
+ return selectionToQuery(config, fieldState);
379
379
  },
380
380
  (path) => {
381
381
  const returnType = getNamedType(field.type);
@@ -429,7 +429,7 @@ export function queryFromInfo<T extends SelectionMap>({
429
429
 
430
430
  setLoaderMappings(options.context, options.info, state.mappings);
431
431
 
432
- const query = selectionToQuery(state) as T;
432
+ const query = selectionToQuery(options.config, state) as T;
433
433
 
434
434
  return withUsageCheck ? wrapWithUsageCheck(query) : query;
435
435
  }
@@ -445,6 +445,12 @@ export function stateFromInfo<T extends SelectionMap>({
445
445
  }: QueryFromInfoOptions<T>) {
446
446
  const returnType = getNamedType(info.returnType);
447
447
  const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
448
+ const initialSelection = select
449
+ ? {
450
+ columns: {},
451
+ ...select,
452
+ }
453
+ : undefined;
448
454
 
449
455
  let state: SelectionState | undefined;
450
456
 
@@ -470,7 +476,13 @@ export function stateFromInfo<T extends SelectionMap>({
470
476
  : [path.map((n) => (typeof n === 'string' ? { name: n } : n))],
471
477
  subPath,
472
478
  (resolvedType, resolvedField, nested, deferred) => {
473
- state = createStateForSelection(config, info, resolvedType, undefined, select);
479
+ state = createStateForSelection(
480
+ config,
481
+ info,
482
+ resolvedType,
483
+ undefined,
484
+ initialSelection,
485
+ );
474
486
 
475
487
  addTypeSelectionsForField(
476
488
  config,
@@ -488,13 +500,13 @@ export function stateFromInfo<T extends SelectionMap>({
488
500
  },
489
501
  );
490
502
  } else {
491
- state = createStateForSelection(config, info, type, undefined, select);
503
+ state = createStateForSelection(config, info, type, undefined, initialSelection);
492
504
 
493
505
  addTypeSelectionsForField(config, type, context, info, state, info.fieldNodes[0], []);
494
506
  }
495
507
 
496
508
  if (!state) {
497
- state = createStateForSelection(config, info, type, undefined, select);
509
+ state = createStateForSelection(config, info, type, undefined, initialSelection);
498
510
  }
499
511
 
500
512
  return state;