@pothos/plugin-drizzle 0.0.1 → 0.2.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 +12 -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 +7 -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 +21 -14
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/config.d.ts +4 -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 +7 -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 +10 -9
- package/esm/src/drizzle-field-builder.js.map +1 -1
- package/esm/src/field-builder.js +4 -4
- 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 +9 -6
- 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 +19 -18
- package/esm/src/schema-builder.js.map +1 -1
- package/esm/src/types.js.map +1 -1
- package/esm/src/utils/config.js +15 -2
- 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 +21 -14
- package/esm/types.d.ts.map +1 -1
- package/esm/utils/config.d.ts +4 -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 +9 -8
- package/lib/src/drizzle-field-builder.js.map +1 -1
- package/lib/src/field-builder.js +4 -4
- 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 +10 -6
- 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 +19 -18
- package/lib/src/schema-builder.js.map +1 -1
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/config.js +26 -5
- 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 +38 -27
- package/src/field-builder.ts +12 -13
- 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 +15 -17
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +5 -3
- package/src/schema-builder.ts +26 -25
- package/src/types.ts +54 -48
- package/src/utils/config.ts +35 -5
- 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/src/utils/loader-map.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
2
1
|
import { createContextCache } from '@pothos/core';
|
|
2
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
3
3
|
|
|
4
4
|
export type LoaderMappings = Record<
|
|
5
5
|
string,
|
|
@@ -11,7 +11,7 @@ export type LoaderMappings = Record<
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
const cache = createContextCache((
|
|
14
|
+
const cache = createContextCache(() => new Map<string, LoaderMappings>());
|
|
15
15
|
|
|
16
16
|
export function cacheKey(type: string, path: GraphQLResolveInfo['path'], subPath: string[] = []) {
|
|
17
17
|
let key = '';
|
|
@@ -32,15 +32,13 @@ export function cacheKey(type: string, path: GraphQLResolveInfo['path'], subPath
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, value: LoaderMappings) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const mapping = value[field];
|
|
35
|
+
const map = cache(ctx);
|
|
36
|
+
for (const [field, mapping] of Object.entries(value)) {
|
|
39
37
|
const subPath = [...mapping.indirectPath, field];
|
|
40
38
|
const key = cacheKey(mapping.type, info.path, subPath);
|
|
41
39
|
|
|
42
40
|
map.set(key, mapping.mappings);
|
|
43
|
-
}
|
|
41
|
+
}
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
export function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string) {
|
package/src/utils/map-query.ts
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
import { PothosValidationError } from '@pothos/core';
|
|
2
2
|
import {
|
|
3
|
-
DBQueryConfig,
|
|
3
|
+
type DBQueryConfig,
|
|
4
4
|
RelationalSchemaConfig,
|
|
5
|
-
TableRelationalConfig,
|
|
5
|
+
type TableRelationalConfig,
|
|
6
6
|
TablesRelationalConfig,
|
|
7
7
|
} from 'drizzle-orm';
|
|
8
8
|
import {
|
|
9
|
-
FieldNode,
|
|
10
|
-
FragmentDefinitionNode,
|
|
9
|
+
type FieldNode,
|
|
10
|
+
type FragmentDefinitionNode,
|
|
11
|
+
type GraphQLField,
|
|
12
|
+
GraphQLIncludeDirective,
|
|
13
|
+
type GraphQLInterfaceType,
|
|
14
|
+
type GraphQLNamedType,
|
|
15
|
+
type GraphQLObjectType,
|
|
16
|
+
type GraphQLResolveInfo,
|
|
17
|
+
GraphQLSkipDirective,
|
|
18
|
+
type InlineFragmentNode,
|
|
19
|
+
Kind,
|
|
20
|
+
type SelectionSetNode,
|
|
11
21
|
getArgumentValues,
|
|
12
22
|
getDirectiveValues,
|
|
13
23
|
getNamedType,
|
|
14
|
-
GraphQLField,
|
|
15
|
-
GraphQLIncludeDirective,
|
|
16
|
-
GraphQLInterfaceType,
|
|
17
|
-
GraphQLNamedType,
|
|
18
|
-
GraphQLObjectType,
|
|
19
|
-
GraphQLResolveInfo,
|
|
20
|
-
GraphQLSkipDirective,
|
|
21
|
-
InlineFragmentNode,
|
|
22
24
|
isInterfaceType,
|
|
23
25
|
isObjectType,
|
|
24
|
-
Kind,
|
|
25
|
-
SelectionSetNode,
|
|
26
26
|
} from 'graphql';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import { LoaderMappings, setLoaderMappings } from './loader-map';
|
|
27
|
+
import type { DrizzleFieldSelection } from '../types';
|
|
28
|
+
import type { PothosDrizzleSchemaConfig } from './config';
|
|
29
|
+
import { type LoaderMappings, setLoaderMappings } from './loader-map';
|
|
30
30
|
import {
|
|
31
|
+
type SelectionMap,
|
|
32
|
+
type SelectionState,
|
|
31
33
|
createState,
|
|
32
34
|
mergeSelection,
|
|
33
35
|
selectionCompatible,
|
|
34
|
-
SelectionMap,
|
|
35
|
-
SelectionState,
|
|
36
36
|
selectionToQuery,
|
|
37
37
|
} from './selections';
|
|
38
38
|
import { wrapWithUsageCheck } from './usage';
|
|
39
|
-
import { PothosDrizzleSchemaConfig } from './config';
|
|
40
39
|
|
|
41
40
|
export interface IndirectInclude {
|
|
42
41
|
getType: () => string;
|
|
@@ -348,7 +347,6 @@ function addFieldSelection(
|
|
|
348
347
|
);
|
|
349
348
|
}
|
|
350
349
|
addTypeSelectionsForField(config, returnType, context, info, fieldState, selection, []);
|
|
351
|
-
// eslint-disable-next-line prefer-destructuring
|
|
352
350
|
mappings = fieldState.mappings;
|
|
353
351
|
return selectionToQuery(fieldState);
|
|
354
352
|
},
|
|
@@ -376,7 +374,6 @@ function addFieldSelection(
|
|
|
376
374
|
|
|
377
375
|
if (fieldSelect && selectionCompatible(state, fieldSelectionMap, true)) {
|
|
378
376
|
mergeSelection(config, state, fieldSelectionMap);
|
|
379
|
-
// eslint-disable-next-line no-param-reassign
|
|
380
377
|
state.mappings[selection.alias?.value ?? selection.name.value] = {
|
|
381
378
|
field: selection.name.value,
|
|
382
379
|
type: type.name,
|
package/src/utils/refs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SchemaTypes } from '@pothos/core';
|
|
2
|
-
import { DrizzleInterfaceRef, DrizzleRef } from '../interface-ref';
|
|
1
|
+
import type { SchemaTypes } from '@pothos/core';
|
|
2
|
+
import { DrizzleInterfaceRef, type DrizzleRef } from '../interface-ref';
|
|
3
3
|
import { DrizzleObjectRef } from '../object-ref';
|
|
4
4
|
|
|
5
5
|
export const refMap = new WeakMap<object, Map<string, DrizzleRef<never>>>();
|
package/src/utils/selections.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { PothosValidationError } from '@pothos/core';
|
|
2
2
|
import {
|
|
3
|
-
DBQueryConfig,
|
|
3
|
+
type DBQueryConfig,
|
|
4
4
|
RelationalSchemaConfig,
|
|
5
|
-
SQL,
|
|
6
|
-
TableRelationalConfig,
|
|
5
|
+
type SQL,
|
|
6
|
+
type TableRelationalConfig,
|
|
7
7
|
TablesRelationalConfig,
|
|
8
8
|
getOperators,
|
|
9
9
|
} from 'drizzle-orm';
|
|
10
|
-
import {
|
|
10
|
+
import type { PothosDrizzleSchemaConfig } from './config';
|
|
11
11
|
import { deepEqual } from './deep-equal';
|
|
12
|
-
import { LoaderMappings } from './loader-map';
|
|
13
|
-
import { PothosDrizzleSchemaConfig } from './config';
|
|
12
|
+
import type { LoaderMappings } from './loader-map';
|
|
14
13
|
|
|
15
14
|
export interface SelectionState {
|
|
16
15
|
table: TableRelationalConfig;
|
|
@@ -123,7 +122,7 @@ export function mergeSelection(
|
|
|
123
122
|
{ with: withSelection, extras, columns, ...query }: SelectionMap,
|
|
124
123
|
) {
|
|
125
124
|
if (withSelection) {
|
|
126
|
-
|
|
125
|
+
for (const [key, value] of Object.entries(withSelection)) {
|
|
127
126
|
const relation = state.table.relations[key];
|
|
128
127
|
|
|
129
128
|
if (!relation) {
|
|
@@ -131,7 +130,7 @@ export function mergeSelection(
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
merge(config.dbToSchema[relation.referencedTableName], key, value as SelectionMap | boolean);
|
|
134
|
-
}
|
|
133
|
+
}
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
if (Object.keys(query).length > 0) {
|
package/src/utils/usage.ts
CHANGED
|
@@ -20,7 +20,6 @@ export function wrapWithUsageCheck<T extends Object>(obj: T): T {
|
|
|
20
20
|
Object.defineProperty(result, key, {
|
|
21
21
|
enumerable: true,
|
|
22
22
|
configurable: true,
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
24
23
|
get() {
|
|
25
24
|
used = true;
|
|
26
25
|
return obj[key as keyof T];
|
|
@@ -47,7 +46,6 @@ export function extendWithUsage<T extends object, U extends object>(
|
|
|
47
46
|
|
|
48
47
|
for (const key of [usageSymbol, ...Object.keys(original)]) {
|
|
49
48
|
if (key in result) {
|
|
50
|
-
// eslint-disable-next-line no-continue
|
|
51
49
|
continue;
|
|
52
50
|
}
|
|
53
51
|
|