@pothos/plugin-drizzle 0.0.1 → 0.1.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 +6 -0
- package/drizzle/meta/_journal.json +1 -1
- package/dts/drizzle-field-builder.d.ts +9 -9
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +7 -7
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +2 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +2 -2
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +5 -5
- 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 +1 -1
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/types.d.ts +10 -9
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/config.d.ts +2 -2
- package/dts/utils/config.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +7 -7
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/deep-equal.d.ts.map +1 -1
- package/dts/utils/drizzle-graphql.d.ts +1 -1
- package/dts/utils/drizzle-graphql.d.ts.map +1 -1
- package/dts/utils/loader-map.d.ts +1 -1
- package/dts/utils/loader-map.d.ts.map +1 -1
- package/dts/utils/map-query.d.ts +3 -3
- package/dts/utils/map-query.d.ts.map +1 -1
- package/dts/utils/refs.d.ts +2 -2
- package/dts/utils/refs.d.ts.map +1 -1
- package/dts/utils/selections.d.ts +3 -3
- package/dts/utils/selections.d.ts.map +1 -1
- package/dts/utils/usage.d.ts.map +1 -1
- package/esm/drizzle-field-builder.d.ts +9 -9
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/global-types.d.ts +7 -7
- package/esm/global-types.d.ts.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/interface-ref.d.ts +2 -2
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/model-loader.d.ts +5 -5
- package/esm/model-loader.d.ts.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 +1 -1
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/src/drizzle-field-builder.js +4 -4
- package/esm/src/drizzle-field-builder.js.map +1 -1
- package/esm/src/field-builder.js +2 -2
- package/esm/src/field-builder.js.map +1 -1
- package/esm/src/global-types.js +1 -1
- package/esm/src/global-types.js.map +1 -1
- package/esm/src/index.js +4 -4
- package/esm/src/index.js.map +1 -1
- package/esm/src/interface-ref.js.map +1 -1
- package/esm/src/model-loader.js +6 -5
- package/esm/src/model-loader.js.map +1 -1
- package/esm/src/object-ref.js +4 -2
- package/esm/src/object-ref.js.map +1 -1
- package/esm/src/schema-builder.js +5 -5
- package/esm/src/schema-builder.js.map +1 -1
- package/esm/src/types.js.map +1 -1
- package/esm/src/utils/config.js.map +1 -1
- package/esm/src/utils/cursors.js +6 -6
- package/esm/src/utils/cursors.js.map +1 -1
- package/esm/src/utils/deep-equal.js +1 -1
- package/esm/src/utils/deep-equal.js.map +1 -1
- package/esm/src/utils/drizzle-graphql.js +44 -21
- package/esm/src/utils/drizzle-graphql.js.map +1 -1
- package/esm/src/utils/loader-map.js +4 -5
- package/esm/src/utils/loader-map.js.map +1 -1
- package/esm/src/utils/map-query.js +1 -3
- package/esm/src/utils/map-query.js.map +1 -1
- package/esm/src/utils/refs.js.map +1 -1
- package/esm/src/utils/selections.js +3 -3
- package/esm/src/utils/selections.js.map +1 -1
- package/esm/src/utils/usage.js +0 -1
- package/esm/src/utils/usage.js.map +1 -1
- package/esm/types.d.ts +10 -9
- package/esm/types.d.ts.map +1 -1
- package/esm/utils/config.d.ts +2 -2
- package/esm/utils/config.d.ts.map +1 -1
- package/esm/utils/cursors.d.ts +7 -7
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/deep-equal.d.ts.map +1 -1
- package/esm/utils/drizzle-graphql.d.ts +1 -1
- package/esm/utils/drizzle-graphql.d.ts.map +1 -1
- package/esm/utils/loader-map.d.ts +1 -1
- package/esm/utils/loader-map.d.ts.map +1 -1
- package/esm/utils/map-query.d.ts +3 -3
- package/esm/utils/map-query.d.ts.map +1 -1
- package/esm/utils/refs.d.ts +2 -2
- package/esm/utils/refs.d.ts.map +1 -1
- package/esm/utils/selections.d.ts +3 -3
- package/esm/utils/selections.d.ts.map +1 -1
- package/esm/utils/usage.d.ts.map +1 -1
- package/lib/src/drizzle-field-builder.js +3 -3
- package/lib/src/drizzle-field-builder.js.map +1 -1
- package/lib/src/field-builder.js +2 -2
- package/lib/src/field-builder.js.map +1 -1
- package/lib/src/global-types.js +1 -1
- package/lib/src/global-types.js.map +1 -1
- package/lib/src/index.js +4 -4
- package/lib/src/index.js.map +1 -1
- package/lib/src/interface-ref.js.map +1 -1
- package/lib/src/model-loader.js +7 -5
- package/lib/src/model-loader.js.map +1 -1
- package/lib/src/object-ref.js +3 -1
- package/lib/src/object-ref.js.map +1 -1
- package/lib/src/schema-builder.js +5 -5
- package/lib/src/schema-builder.js.map +1 -1
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/config.js.map +1 -1
- package/lib/src/utils/cursors.js +7 -6
- package/lib/src/utils/cursors.js.map +1 -1
- package/lib/src/utils/deep-equal.js +1 -1
- package/lib/src/utils/deep-equal.js.map +1 -1
- package/lib/src/utils/drizzle-graphql.js +53 -21
- package/lib/src/utils/drizzle-graphql.js.map +1 -1
- package/lib/src/utils/loader-map.js +4 -5
- package/lib/src/utils/loader-map.js.map +1 -1
- package/lib/src/utils/map-query.js +2 -4
- package/lib/src/utils/map-query.js.map +1 -1
- package/lib/src/utils/refs.js.map +1 -1
- package/lib/src/utils/selections.js +4 -4
- package/lib/src/utils/selections.js.map +1 -1
- package/lib/src/utils/usage.js +0 -1
- package/lib/src/utils/usage.js.map +1 -1
- package/package.json +11 -11
- package/src/drizzle-field-builder.ts +28 -21
- package/src/field-builder.ts +9 -9
- package/src/global-types.ts +28 -20
- package/src/index.ts +29 -36
- package/src/interface-ref.ts +2 -2
- package/src/model-loader.ts +10 -16
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +5 -3
- package/src/schema-builder.ts +18 -18
- package/src/types.ts +39 -46
- package/src/utils/config.ts +6 -2
- package/src/utils/cursors.ts +21 -22
- package/src/utils/deep-equal.ts +0 -1
- package/src/utils/drizzle-graphql.ts +53 -14
- package/src/utils/loader-map.ts +5 -7
- package/src/utils/map-query.ts +20 -23
- package/src/utils/refs.ts +2 -2
- package/src/utils/selections.ts +8 -9
- package/src/utils/usage.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/plugin-drizzle",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A Pothos plugin for drizzle",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dts/index.d.ts",
|
|
@@ -35,23 +35,23 @@
|
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@pothos/core": "*",
|
|
38
|
-
"graphql": "
|
|
38
|
+
"graphql": ">=16.6.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@libsql/client": "^0.
|
|
41
|
+
"@libsql/client": "^0.8.0",
|
|
42
42
|
"drizzle-graphql": "^0.8.4",
|
|
43
|
-
"drizzle-kit": "^0.23.
|
|
44
|
-
"drizzle-orm": "^0.32.
|
|
43
|
+
"drizzle-kit": "^0.23.1",
|
|
44
|
+
"drizzle-orm": "^0.32.1",
|
|
45
45
|
"graphql": "^16.8.1",
|
|
46
46
|
"graphql-scalars": "^1.23.0",
|
|
47
47
|
"graphql-tag": "^2.12.6",
|
|
48
48
|
"postgres": "^3.4.4",
|
|
49
|
-
"@pothos/
|
|
50
|
-
"@pothos/
|
|
51
|
-
"@pothos/plugin-relay": "4.0
|
|
52
|
-
"@pothos/plugin-scope-auth": "4.0
|
|
53
|
-
"@pothos/plugin-with-input": "4.0
|
|
54
|
-
"@pothos/test-utils": "2.0
|
|
49
|
+
"@pothos/plugin-add-graphql": "4.1.0",
|
|
50
|
+
"@pothos/core": "4.1.0",
|
|
51
|
+
"@pothos/plugin-relay": "4.1.0",
|
|
52
|
+
"@pothos/plugin-scope-auth": "4.1.0",
|
|
53
|
+
"@pothos/plugin-with-input": "4.1.0",
|
|
54
|
+
"@pothos/test-utils": "2.1.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"type": "tsc --project tsconfig.type.json",
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import { getOperators, InferModelFromColumns, Many, TableRelationalConfig } from 'drizzle-orm';
|
|
2
1
|
import {
|
|
3
|
-
CompatibleTypes,
|
|
4
|
-
ExposeNullability,
|
|
5
|
-
FieldKind,
|
|
6
|
-
FieldRef,
|
|
7
|
-
InputFieldMap,
|
|
8
|
-
InterfaceParam,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
NormalizeArgs,
|
|
2
|
+
type CompatibleTypes,
|
|
3
|
+
type ExposeNullability,
|
|
4
|
+
type FieldKind,
|
|
5
|
+
type FieldRef,
|
|
6
|
+
type InputFieldMap,
|
|
7
|
+
type InterfaceParam,
|
|
8
|
+
type MaybePromise,
|
|
9
|
+
type NormalizeArgs,
|
|
12
10
|
ObjectRef,
|
|
13
|
-
PluginName,
|
|
11
|
+
type PluginName,
|
|
14
12
|
PothosSchemaError,
|
|
15
13
|
RootFieldBuilder,
|
|
16
|
-
SchemaTypes,
|
|
17
|
-
ShapeFromTypeParam,
|
|
18
|
-
TypeParam,
|
|
14
|
+
type SchemaTypes,
|
|
15
|
+
type ShapeFromTypeParam,
|
|
16
|
+
type TypeParam,
|
|
17
|
+
isThenable,
|
|
19
18
|
} from '@pothos/core';
|
|
20
19
|
import {
|
|
20
|
+
type InferModelFromColumns,
|
|
21
|
+
Many,
|
|
22
|
+
type TableRelationalConfig,
|
|
23
|
+
getOperators,
|
|
24
|
+
} from 'drizzle-orm';
|
|
25
|
+
import type { DrizzleRef } from './interface-ref';
|
|
26
|
+
import type {
|
|
21
27
|
DrizzleConnectionShape,
|
|
22
28
|
ListRelation,
|
|
23
29
|
RelatedConnectionOptions,
|
|
@@ -26,18 +32,16 @@ import {
|
|
|
26
32
|
TypesForRelation,
|
|
27
33
|
VariantFieldOptions,
|
|
28
34
|
} from './types';
|
|
29
|
-
import { getRefFromModel } from './utils/refs';
|
|
30
35
|
import {
|
|
31
36
|
drizzleCursorConnectionQuery,
|
|
32
37
|
getCursorFormatter,
|
|
33
38
|
wrapConnectionResult,
|
|
34
39
|
} from './utils/cursors';
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
40
|
+
import { getRefFromModel } from './utils/refs';
|
|
41
|
+
import type { SelectionMap } from './utils/selections';
|
|
37
42
|
|
|
38
43
|
// Workaround for FieldKind not being extended on Builder classes
|
|
39
44
|
const RootBuilder: {
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/prefer-function-type
|
|
41
45
|
new <Types extends SchemaTypes, Shape, Kind extends FieldKind>(
|
|
42
46
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
43
47
|
kind: FieldKind,
|
|
@@ -236,7 +240,7 @@ export class DrizzleObjectFieldBuilder<
|
|
|
236
240
|
const relationSelect = (
|
|
237
241
|
args: object,
|
|
238
242
|
context: object,
|
|
239
|
-
nestedQuery: (query: unknown, path?: unknown) => { select?:
|
|
243
|
+
nestedQuery: (query: unknown, path?: unknown) => { select?: object },
|
|
240
244
|
) => {
|
|
241
245
|
typeName ??= this.builder.configStore.getTypeConfig(ref).name;
|
|
242
246
|
const nested = nestedQuery(getQuery(args, context).select, {
|
|
@@ -326,8 +330,11 @@ export class DrizzleObjectFieldBuilder<
|
|
|
326
330
|
const ref: DrizzleRef<Types> =
|
|
327
331
|
typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
|
|
328
332
|
|
|
329
|
-
const selfSelect = (
|
|
330
|
-
|
|
333
|
+
const selfSelect = (
|
|
334
|
+
_args: object,
|
|
335
|
+
_context: object,
|
|
336
|
+
nestedQuery: (query: unknown) => unknown,
|
|
337
|
+
) => nestedQuery({});
|
|
331
338
|
|
|
332
339
|
return this.field({
|
|
333
340
|
...(options as {}),
|
package/src/field-builder.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type FieldKind, ObjectRef, RootFieldBuilder, type SchemaTypes } from '@pothos/core';
|
|
2
|
+
import type { FieldRef } from '@pothos/core';
|
|
3
|
+
import type { TableRelationalConfig } from 'drizzle-orm';
|
|
4
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
5
|
+
import type { DrizzleRef } from './interface-ref';
|
|
6
|
+
import type { DrizzleConnectionFieldOptions } from './types';
|
|
7
|
+
import { getSchemaConfig } from './utils/config';
|
|
8
|
+
import { resolveDrizzleCursorConnection } from './utils/cursors';
|
|
3
9
|
import { queryFromInfo } from './utils/map-query';
|
|
4
10
|
import { getRefFromModel } from './utils/refs';
|
|
5
|
-
import { FieldRef } from '@pothos/core';
|
|
6
|
-
import { DrizzleRef } from './interface-ref';
|
|
7
|
-
import { DrizzleConnectionFieldOptions } from './types';
|
|
8
|
-
import { TableRelationalConfig } from 'drizzle-orm';
|
|
9
|
-
import { resolveDrizzleCursorConnection } from './utils/cursors';
|
|
10
|
-
import { getSchemaConfig } from './utils/config';
|
|
11
11
|
|
|
12
12
|
const fieldBuilderProto = RootFieldBuilder.prototype as PothosSchemaTypes.RootFieldBuilder<
|
|
13
13
|
SchemaTypes,
|
|
@@ -158,7 +158,7 @@ fieldBuilderProto.drizzleConnection = function drizzleConnection<
|
|
|
158
158
|
: {
|
|
159
159
|
...connectionOptions,
|
|
160
160
|
extensions: {
|
|
161
|
-
...(connectionOptions as Record<string,
|
|
161
|
+
...(connectionOptions as Record<string, object> | undefined)?.extensions,
|
|
162
162
|
},
|
|
163
163
|
},
|
|
164
164
|
edgeOptions,
|
package/src/global-types.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
3
1
|
import type {
|
|
4
|
-
BuildQueryResult,
|
|
5
|
-
DBQueryConfig,
|
|
6
|
-
ExtractTablesWithRelations,
|
|
7
|
-
SQL,
|
|
8
|
-
TableRelationalConfig,
|
|
9
|
-
} from 'drizzle-orm';
|
|
10
|
-
import {
|
|
11
2
|
FieldKind,
|
|
12
3
|
FieldMap,
|
|
13
4
|
FieldNullability,
|
|
@@ -21,9 +12,16 @@ import {
|
|
|
21
12
|
ShapeFromTypeParam,
|
|
22
13
|
TypeParam,
|
|
23
14
|
} from '@pothos/core';
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
import type {
|
|
16
|
+
BuildQueryResult,
|
|
17
|
+
DBQueryConfig,
|
|
18
|
+
ExtractTablesWithRelations,
|
|
19
|
+
SQL,
|
|
20
|
+
TableRelationalConfig,
|
|
21
|
+
} from 'drizzle-orm';
|
|
22
|
+
import type { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
|
|
23
|
+
import type { DrizzleInterfaceRef, DrizzleRef } from './interface-ref';
|
|
24
|
+
import type { DrizzleObjectRef, drizzleTableKey } from './object-ref';
|
|
27
25
|
import type {
|
|
28
26
|
AddGraphQLInputTypeOptions,
|
|
29
27
|
DrizzleConnectionFieldOptions,
|
|
@@ -35,13 +33,13 @@ import type {
|
|
|
35
33
|
DrizzleObjectFieldOptions,
|
|
36
34
|
DrizzleObjectOptions,
|
|
37
35
|
DrizzlePluginOptions,
|
|
38
|
-
drizzleTableName,
|
|
39
36
|
ShapeFromConnection,
|
|
37
|
+
drizzleTableName,
|
|
40
38
|
} from './types';
|
|
41
39
|
|
|
40
|
+
import type { GraphQLInputObjectType } from 'graphql';
|
|
42
41
|
import type { PothosDrizzlePlugin } from '.';
|
|
43
|
-
import { DrizzleNodeRef } from './node-ref';
|
|
44
|
-
import { GraphQLInputObjectType } from 'graphql';
|
|
42
|
+
import type { DrizzleNodeRef } from './node-ref';
|
|
45
43
|
|
|
46
44
|
declare global {
|
|
47
45
|
export namespace PothosSchemaTypes {
|
|
@@ -274,7 +272,9 @@ declare global {
|
|
|
274
272
|
Param extends
|
|
275
273
|
| keyof Types['DrizzleRelationSchema']
|
|
276
274
|
| [keyof Types['DrizzleRelationSchema']]
|
|
275
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
277
276
|
| DrizzleRef<any>
|
|
277
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
278
278
|
| [DrizzleRef<any>],
|
|
279
279
|
Nullable extends FieldNullability<Type>,
|
|
280
280
|
ResolveShape,
|
|
@@ -284,9 +284,11 @@ declare global {
|
|
|
284
284
|
? Param
|
|
285
285
|
: Param extends [keyof Types['DrizzleRelationSchema']]
|
|
286
286
|
? Param[0]
|
|
287
|
-
:
|
|
287
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
288
|
+
Param extends DrizzleRef<any, infer T>
|
|
288
289
|
? T & keyof Types['DrizzleRelationSchema']
|
|
289
|
-
:
|
|
290
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
291
|
+
Param extends [DrizzleRef<any, infer T>]
|
|
290
292
|
? T & keyof Types['DrizzleRelationSchema']
|
|
291
293
|
: never,
|
|
292
294
|
Type extends TypeParam<Types> = ObjectRef<
|
|
@@ -314,12 +316,13 @@ declare global {
|
|
|
314
316
|
|
|
315
317
|
drizzleConnection: 'relay' extends PluginName
|
|
316
318
|
? <
|
|
317
|
-
Type extends
|
|
319
|
+
Type extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
318
320
|
| DrizzleRef<any, keyof Types['DrizzleRelationSchema']>
|
|
319
321
|
| keyof Types['DrizzleRelationSchema'],
|
|
320
322
|
Nullable extends boolean,
|
|
321
323
|
ResolveReturnShape,
|
|
322
324
|
Args extends InputFieldMap = {},
|
|
325
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
323
326
|
Shape = Type extends DrizzleRef<any, keyof Types['DrizzleRelationSchema'], infer S>
|
|
324
327
|
? S
|
|
325
328
|
: BuildQueryResult<
|
|
@@ -334,6 +337,7 @@ declare global {
|
|
|
334
337
|
Types,
|
|
335
338
|
ParentShape,
|
|
336
339
|
Type,
|
|
340
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
337
341
|
Types['DrizzleRelationSchema'][Type extends DrizzleRef<any, infer K>
|
|
338
342
|
? K
|
|
339
343
|
: Type & keyof Types['DrizzleRelationSchema']],
|
|
@@ -386,7 +390,9 @@ declare global {
|
|
|
386
390
|
Param extends
|
|
387
391
|
| keyof Types['DrizzleRelationSchema']
|
|
388
392
|
| [keyof Types['DrizzleRelationSchema']]
|
|
393
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
389
394
|
| DrizzleRef<any>
|
|
395
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
390
396
|
| [DrizzleRef<any>],
|
|
391
397
|
Nullable extends FieldNullability<Type>,
|
|
392
398
|
ResolveShape,
|
|
@@ -398,9 +404,11 @@ declare global {
|
|
|
398
404
|
? Param
|
|
399
405
|
: Param extends [keyof Types['DrizzleRelationSchema']]
|
|
400
406
|
? Param[0]
|
|
401
|
-
:
|
|
407
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
408
|
+
Param extends DrizzleRef<any, infer T>
|
|
402
409
|
? T & keyof Types['DrizzleRelationSchema']
|
|
403
|
-
:
|
|
410
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
411
|
+
Param extends [DrizzleRef<any, infer T>]
|
|
404
412
|
? T & keyof Types['DrizzleRelationSchema']
|
|
405
413
|
: never,
|
|
406
414
|
Type extends TypeParam<Types> = ObjectRef<
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import './global-types';
|
|
2
2
|
import './field-builder';
|
|
3
3
|
import './schema-builder';
|
|
4
|
-
import { GraphQLFieldResolver } from 'graphql';
|
|
5
4
|
import SchemaBuilder, {
|
|
6
5
|
BasePlugin,
|
|
7
6
|
createInputValueMapper,
|
|
8
7
|
mapInputFields,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
SchemaTypes,
|
|
8
|
+
type PothosOutputFieldConfig,
|
|
9
|
+
type SchemaTypes,
|
|
12
10
|
} from '@pothos/core';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import type { GraphQLFieldResolver } from 'graphql';
|
|
12
|
+
import type { ModelLoader } from './model-loader';
|
|
13
|
+
import type { DrizzleGraphQLInputExtensions } from './types';
|
|
15
14
|
import {
|
|
16
15
|
extractFilters,
|
|
17
16
|
extractOrderBy,
|
|
@@ -44,37 +43,31 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
44
43
|
);
|
|
45
44
|
|
|
46
45
|
const argMapper = argMappings
|
|
47
|
-
? createInputValueMapper(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
)
|
|
46
|
+
? createInputValueMapper(argMappings, (input, mappings) => {
|
|
47
|
+
if (!mappings.value) {
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { table, tableConfig, inputType } = mappings.value;
|
|
52
|
+
|
|
53
|
+
switch (inputType) {
|
|
54
|
+
case 'orderBy':
|
|
55
|
+
return extractOrderBy(tableConfig, input as never);
|
|
56
|
+
case 'filters':
|
|
57
|
+
return extractFilters(tableConfig, table, input as never);
|
|
58
|
+
case 'insert':
|
|
59
|
+
return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
60
|
+
case 'update':
|
|
61
|
+
return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Unknown drizzle input type: ${inputType}`);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
71
67
|
: null;
|
|
72
68
|
|
|
73
69
|
const argMappers: typeof fieldConfig.argMappers = argMapper
|
|
74
|
-
? [
|
|
75
|
-
...(fieldConfig.argMappers ?? []),
|
|
76
|
-
(args, context, info) => argMapper(args, undefined, context, info),
|
|
77
|
-
]
|
|
70
|
+
? [...(fieldConfig.argMappers ?? []), (args) => argMapper(args, undefined)]
|
|
78
71
|
: fieldConfig.argMappers;
|
|
79
72
|
|
|
80
73
|
if (fieldConfig.kind === 'DrizzleObject' && fieldConfig.pothosOptions.select) {
|
|
@@ -121,12 +114,12 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
121
114
|
const parentTypes = new Set([fieldConfig.parentType]);
|
|
122
115
|
|
|
123
116
|
if (parentConfig.kind === 'Interface' || parentConfig.kind === 'Object') {
|
|
124
|
-
parentConfig.interfaces
|
|
117
|
+
for (const iface of parentConfig.interfaces) {
|
|
125
118
|
const interfaceConfig = this.buildCache.getTypeConfig(iface, 'Interface');
|
|
126
119
|
if (interfaceConfig.extensions?.pothosDrizzleModel) {
|
|
127
120
|
parentTypes.add(interfaceConfig.name);
|
|
128
121
|
}
|
|
129
|
-
}
|
|
122
|
+
}
|
|
130
123
|
}
|
|
131
124
|
|
|
132
125
|
const modelLoader = parentConfig.extensions?.pothosDrizzleLoader as ReturnType<
|
package/src/interface-ref.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InterfaceRef, SchemaTypes } from '@pothos/core';
|
|
2
|
-
import { DrizzleObjectRef, drizzleTableKey } from './object-ref';
|
|
1
|
+
import { InterfaceRef, type SchemaTypes } from '@pothos/core';
|
|
2
|
+
import { type DrizzleObjectRef, drizzleTableKey } from './object-ref';
|
|
3
3
|
|
|
4
4
|
export type DrizzleRef<
|
|
5
5
|
Types extends SchemaTypes,
|
package/src/model-loader.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
RelationalSchemaConfig,
|
|
6
|
-
sql,
|
|
7
|
-
TableRelationalConfig,
|
|
8
|
-
TablesRelationalConfig,
|
|
9
|
-
} from 'drizzle-orm';
|
|
10
|
-
import { createContextCache, SchemaTypes } from '@pothos/core';
|
|
1
|
+
import { type SchemaTypes, createContextCache } from '@pothos/core';
|
|
2
|
+
import { type Column, type TableRelationalConfig, inArray, sql } from 'drizzle-orm';
|
|
3
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
4
|
+
import { type PothosDrizzleSchemaConfig, getSchemaConfig } from './utils/config';
|
|
11
5
|
import { cacheKey, setLoaderMappings } from './utils/loader-map';
|
|
12
6
|
import { selectionStateFromInfo, stateFromInfo } from './utils/map-query';
|
|
13
7
|
import {
|
|
8
|
+
type SelectionMap,
|
|
9
|
+
type SelectionState,
|
|
14
10
|
mergeSelection,
|
|
15
11
|
selectionCompatible,
|
|
16
|
-
SelectionMap,
|
|
17
|
-
SelectionState,
|
|
18
12
|
selectionToQuery,
|
|
19
13
|
} from './utils/selections';
|
|
20
|
-
import { getSchemaConfig, PothosDrizzleSchemaConfig } from './utils/config';
|
|
21
14
|
|
|
22
15
|
interface ResolvablePromise<T> {
|
|
23
16
|
promise: Promise<T>;
|
|
@@ -144,7 +137,7 @@ export class ModelLoader {
|
|
|
144
137
|
return result;
|
|
145
138
|
}
|
|
146
139
|
|
|
147
|
-
|
|
140
|
+
stageQuery(selection: SelectionState, query: SelectionMap, model: object) {
|
|
148
141
|
for (const entry of this.staged) {
|
|
149
142
|
if (selectionCompatible(entry.state, query)) {
|
|
150
143
|
mergeSelection(this.config, entry.state, query);
|
|
@@ -198,10 +191,11 @@ export class ModelLoader {
|
|
|
198
191
|
|
|
199
192
|
if (result) {
|
|
200
193
|
promise.resolve(result ?? null);
|
|
201
|
-
} else
|
|
194
|
+
} else {
|
|
202
195
|
promise.reject(
|
|
203
196
|
new Error(`Model ${this.modelName}(${this.sqlForModel(model)}) not found`),
|
|
204
197
|
);
|
|
198
|
+
}
|
|
205
199
|
}
|
|
206
200
|
},
|
|
207
201
|
(err) => {
|
|
@@ -217,7 +211,7 @@ export class ModelLoader {
|
|
|
217
211
|
}
|
|
218
212
|
});
|
|
219
213
|
|
|
220
|
-
setTimeout(() =>
|
|
214
|
+
setTimeout(() => nextTick.resolve(), 0);
|
|
221
215
|
|
|
222
216
|
return promise.promise;
|
|
223
217
|
}
|
package/src/node-ref.ts
CHANGED
package/src/object-ref.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ObjectRef,
|
|
3
|
+
type SchemaTypes,
|
|
2
4
|
abstractReturnShapeKey,
|
|
3
5
|
brandWithType,
|
|
4
|
-
ObjectRef,
|
|
5
|
-
SchemaTypes,
|
|
6
6
|
typeBrandKey,
|
|
7
7
|
} from '@pothos/core';
|
|
8
8
|
import type { WithBrand } from './types';
|
|
@@ -30,7 +30,9 @@ export class DrizzleObjectRef<
|
|
|
30
30
|
value: V,
|
|
31
31
|
): V extends T[] ? { [K in keyof V]: WithBrand<V[K]> } : WithBrand<V> {
|
|
32
32
|
if (Array.isArray(value)) {
|
|
33
|
-
|
|
33
|
+
for (const val of value) {
|
|
34
|
+
brandWithType(val, this.name as never);
|
|
35
|
+
}
|
|
34
36
|
|
|
35
37
|
return value as never;
|
|
36
38
|
}
|
package/src/schema-builder.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import SchemaBuilder, {
|
|
2
2
|
brandWithType,
|
|
3
3
|
completeValue,
|
|
4
|
-
InterfaceRef,
|
|
5
|
-
ObjectRef,
|
|
6
|
-
OutputType,
|
|
4
|
+
type InterfaceRef,
|
|
5
|
+
type ObjectRef,
|
|
6
|
+
type OutputType,
|
|
7
7
|
PothosError,
|
|
8
|
-
SchemaTypes,
|
|
9
|
-
FieldRef,
|
|
10
|
-
InputObjectRef,
|
|
8
|
+
type SchemaTypes,
|
|
9
|
+
type FieldRef,
|
|
10
|
+
type InputObjectRef,
|
|
11
11
|
} from '@pothos/core';
|
|
12
|
+
import type { GraphQLInputObjectType, GraphQLResolveInfo } from 'graphql';
|
|
12
13
|
import { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
|
|
13
|
-
import {
|
|
14
|
+
import { DrizzleInterfaceRef } from './interface-ref';
|
|
15
|
+
import { ModelLoader } from './model-loader';
|
|
16
|
+
import { DrizzleNodeRef } from './node-ref';
|
|
14
17
|
import { DrizzleObjectRef } from './object-ref';
|
|
15
|
-
import { DrizzleGraphQLInputExtensions, DrizzleNodeOptions } from './types';
|
|
18
|
+
import type { DrizzleGraphQLInputExtensions, DrizzleNodeOptions } from './types';
|
|
16
19
|
import { getColumnParser, getColumnSerializer } from './utils/cursors';
|
|
17
|
-
import {
|
|
18
|
-
import { GraphQLInputObjectType, GraphQLResolveInfo } from 'graphql';
|
|
19
|
-
import { ModelLoader } from './model-loader';
|
|
20
|
-
import { DrizzleInterfaceRef } from './interface-ref';
|
|
20
|
+
import { getRefFromModel } from './utils/refs';
|
|
21
21
|
|
|
22
22
|
const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;
|
|
23
23
|
|
|
@@ -139,12 +139,12 @@ schemaBuilderProto.drizzleNode = function drizzleNode(
|
|
|
139
139
|
globalID: (options: Record<string, unknown>) => FieldRef<SchemaTypes, unknown>;
|
|
140
140
|
}
|
|
141
141
|
).globalID({
|
|
142
|
-
...(this.options as { relayOptions?: { idFieldOptions?:
|
|
142
|
+
...(this.options as { relayOptions?: { idFieldOptions?: object } }).relayOptions
|
|
143
143
|
?.idFieldOptions,
|
|
144
144
|
...idOptions,
|
|
145
145
|
nullable: false,
|
|
146
146
|
args: {},
|
|
147
|
-
resolve: (parent: never
|
|
147
|
+
resolve: (parent: never) =>
|
|
148
148
|
completeValue(resolve(parent), (id) => ({
|
|
149
149
|
type: nodeConfig.name,
|
|
150
150
|
id,
|
|
@@ -198,7 +198,7 @@ schemaBuilderProto.drizzleGraphQLOrderBy = function drizzleGraphQLOrderBy(
|
|
|
198
198
|
this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
|
|
199
199
|
table: string,
|
|
200
200
|
type: GraphQLInputObjectType,
|
|
201
|
-
options?: { extensions?:
|
|
201
|
+
options?: { extensions?: object },
|
|
202
202
|
) {
|
|
203
203
|
return (
|
|
204
204
|
this as typeof this & {
|
|
@@ -224,7 +224,7 @@ schemaBuilderProto.drizzleGraphQLFilters = function drizzleGraphQLFilters(
|
|
|
224
224
|
this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
|
|
225
225
|
table: string,
|
|
226
226
|
type: GraphQLInputObjectType,
|
|
227
|
-
options?: { extensions?:
|
|
227
|
+
options?: { extensions?: object },
|
|
228
228
|
) {
|
|
229
229
|
return (
|
|
230
230
|
this as typeof this & {
|
|
@@ -250,7 +250,7 @@ schemaBuilderProto.drizzleGraphQLInsert = function drizzleGraphQLInsert(
|
|
|
250
250
|
this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
|
|
251
251
|
table: string,
|
|
252
252
|
type: GraphQLInputObjectType,
|
|
253
|
-
options?: { extensions?:
|
|
253
|
+
options?: { extensions?: object },
|
|
254
254
|
) {
|
|
255
255
|
return (
|
|
256
256
|
this as typeof this & {
|
|
@@ -276,7 +276,7 @@ schemaBuilderProto.drizzleGraphQLUpdate = function drizzleGraphQLUpdate(
|
|
|
276
276
|
this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
|
|
277
277
|
table: string,
|
|
278
278
|
type: GraphQLInputObjectType,
|
|
279
|
-
options?: { extensions?:
|
|
279
|
+
options?: { extensions?: object },
|
|
280
280
|
) {
|
|
281
281
|
return (
|
|
282
282
|
this as typeof this & {
|