@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.
Files changed (152) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/drizzle/meta/_journal.json +1 -1
  3. package/dts/drizzle-field-builder.d.ts +9 -9
  4. package/dts/drizzle-field-builder.d.ts.map +1 -1
  5. package/dts/global-types.d.ts +7 -7
  6. package/dts/global-types.d.ts.map +1 -1
  7. package/dts/index.d.ts +2 -2
  8. package/dts/index.d.ts.map +1 -1
  9. package/dts/interface-ref.d.ts +2 -2
  10. package/dts/interface-ref.d.ts.map +1 -1
  11. package/dts/model-loader.d.ts +7 -5
  12. package/dts/model-loader.d.ts.map +1 -1
  13. package/dts/node-ref.d.ts +1 -1
  14. package/dts/node-ref.d.ts.map +1 -1
  15. package/dts/object-ref.d.ts +1 -1
  16. package/dts/object-ref.d.ts.map +1 -1
  17. package/dts/types.d.ts +21 -14
  18. package/dts/types.d.ts.map +1 -1
  19. package/dts/utils/config.d.ts +4 -2
  20. package/dts/utils/config.d.ts.map +1 -1
  21. package/dts/utils/cursors.d.ts +7 -7
  22. package/dts/utils/cursors.d.ts.map +1 -1
  23. package/dts/utils/deep-equal.d.ts.map +1 -1
  24. package/dts/utils/drizzle-graphql.d.ts +1 -1
  25. package/dts/utils/drizzle-graphql.d.ts.map +1 -1
  26. package/dts/utils/loader-map.d.ts +1 -1
  27. package/dts/utils/loader-map.d.ts.map +1 -1
  28. package/dts/utils/map-query.d.ts +3 -3
  29. package/dts/utils/map-query.d.ts.map +1 -1
  30. package/dts/utils/refs.d.ts +2 -2
  31. package/dts/utils/refs.d.ts.map +1 -1
  32. package/dts/utils/selections.d.ts +3 -3
  33. package/dts/utils/selections.d.ts.map +1 -1
  34. package/dts/utils/usage.d.ts.map +1 -1
  35. package/esm/drizzle-field-builder.d.ts +9 -9
  36. package/esm/drizzle-field-builder.d.ts.map +1 -1
  37. package/esm/global-types.d.ts +7 -7
  38. package/esm/global-types.d.ts.map +1 -1
  39. package/esm/index.d.ts +2 -2
  40. package/esm/index.d.ts.map +1 -1
  41. package/esm/interface-ref.d.ts +2 -2
  42. package/esm/interface-ref.d.ts.map +1 -1
  43. package/esm/model-loader.d.ts +7 -5
  44. package/esm/model-loader.d.ts.map +1 -1
  45. package/esm/node-ref.d.ts +1 -1
  46. package/esm/node-ref.d.ts.map +1 -1
  47. package/esm/object-ref.d.ts +1 -1
  48. package/esm/object-ref.d.ts.map +1 -1
  49. package/esm/src/drizzle-field-builder.js +10 -9
  50. package/esm/src/drizzle-field-builder.js.map +1 -1
  51. package/esm/src/field-builder.js +4 -4
  52. package/esm/src/field-builder.js.map +1 -1
  53. package/esm/src/global-types.js +1 -1
  54. package/esm/src/global-types.js.map +1 -1
  55. package/esm/src/index.js +4 -4
  56. package/esm/src/index.js.map +1 -1
  57. package/esm/src/interface-ref.js.map +1 -1
  58. package/esm/src/model-loader.js +9 -6
  59. package/esm/src/model-loader.js.map +1 -1
  60. package/esm/src/object-ref.js +4 -2
  61. package/esm/src/object-ref.js.map +1 -1
  62. package/esm/src/schema-builder.js +19 -18
  63. package/esm/src/schema-builder.js.map +1 -1
  64. package/esm/src/types.js.map +1 -1
  65. package/esm/src/utils/config.js +15 -2
  66. package/esm/src/utils/config.js.map +1 -1
  67. package/esm/src/utils/cursors.js +6 -6
  68. package/esm/src/utils/cursors.js.map +1 -1
  69. package/esm/src/utils/deep-equal.js +1 -1
  70. package/esm/src/utils/deep-equal.js.map +1 -1
  71. package/esm/src/utils/drizzle-graphql.js +44 -21
  72. package/esm/src/utils/drizzle-graphql.js.map +1 -1
  73. package/esm/src/utils/loader-map.js +4 -5
  74. package/esm/src/utils/loader-map.js.map +1 -1
  75. package/esm/src/utils/map-query.js +1 -3
  76. package/esm/src/utils/map-query.js.map +1 -1
  77. package/esm/src/utils/refs.js.map +1 -1
  78. package/esm/src/utils/selections.js +3 -3
  79. package/esm/src/utils/selections.js.map +1 -1
  80. package/esm/src/utils/usage.js +0 -1
  81. package/esm/src/utils/usage.js.map +1 -1
  82. package/esm/types.d.ts +21 -14
  83. package/esm/types.d.ts.map +1 -1
  84. package/esm/utils/config.d.ts +4 -2
  85. package/esm/utils/config.d.ts.map +1 -1
  86. package/esm/utils/cursors.d.ts +7 -7
  87. package/esm/utils/cursors.d.ts.map +1 -1
  88. package/esm/utils/deep-equal.d.ts.map +1 -1
  89. package/esm/utils/drizzle-graphql.d.ts +1 -1
  90. package/esm/utils/drizzle-graphql.d.ts.map +1 -1
  91. package/esm/utils/loader-map.d.ts +1 -1
  92. package/esm/utils/loader-map.d.ts.map +1 -1
  93. package/esm/utils/map-query.d.ts +3 -3
  94. package/esm/utils/map-query.d.ts.map +1 -1
  95. package/esm/utils/refs.d.ts +2 -2
  96. package/esm/utils/refs.d.ts.map +1 -1
  97. package/esm/utils/selections.d.ts +3 -3
  98. package/esm/utils/selections.d.ts.map +1 -1
  99. package/esm/utils/usage.d.ts.map +1 -1
  100. package/lib/src/drizzle-field-builder.js +9 -8
  101. package/lib/src/drizzle-field-builder.js.map +1 -1
  102. package/lib/src/field-builder.js +4 -4
  103. package/lib/src/field-builder.js.map +1 -1
  104. package/lib/src/global-types.js +1 -1
  105. package/lib/src/global-types.js.map +1 -1
  106. package/lib/src/index.js +4 -4
  107. package/lib/src/index.js.map +1 -1
  108. package/lib/src/interface-ref.js.map +1 -1
  109. package/lib/src/model-loader.js +10 -6
  110. package/lib/src/model-loader.js.map +1 -1
  111. package/lib/src/object-ref.js +3 -1
  112. package/lib/src/object-ref.js.map +1 -1
  113. package/lib/src/schema-builder.js +19 -18
  114. package/lib/src/schema-builder.js.map +1 -1
  115. package/lib/src/types.js.map +1 -1
  116. package/lib/src/utils/config.js +26 -5
  117. package/lib/src/utils/config.js.map +1 -1
  118. package/lib/src/utils/cursors.js +7 -6
  119. package/lib/src/utils/cursors.js.map +1 -1
  120. package/lib/src/utils/deep-equal.js +1 -1
  121. package/lib/src/utils/deep-equal.js.map +1 -1
  122. package/lib/src/utils/drizzle-graphql.js +53 -21
  123. package/lib/src/utils/drizzle-graphql.js.map +1 -1
  124. package/lib/src/utils/loader-map.js +4 -5
  125. package/lib/src/utils/loader-map.js.map +1 -1
  126. package/lib/src/utils/map-query.js +2 -4
  127. package/lib/src/utils/map-query.js.map +1 -1
  128. package/lib/src/utils/refs.js.map +1 -1
  129. package/lib/src/utils/selections.js +4 -4
  130. package/lib/src/utils/selections.js.map +1 -1
  131. package/lib/src/utils/usage.js +0 -1
  132. package/lib/src/utils/usage.js.map +1 -1
  133. package/package.json +11 -11
  134. package/src/drizzle-field-builder.ts +38 -27
  135. package/src/field-builder.ts +12 -13
  136. package/src/global-types.ts +28 -20
  137. package/src/index.ts +29 -36
  138. package/src/interface-ref.ts +2 -2
  139. package/src/model-loader.ts +15 -17
  140. package/src/node-ref.ts +1 -1
  141. package/src/object-ref.ts +5 -3
  142. package/src/schema-builder.ts +26 -25
  143. package/src/types.ts +54 -48
  144. package/src/utils/config.ts +35 -5
  145. package/src/utils/cursors.ts +21 -22
  146. package/src/utils/deep-equal.ts +0 -1
  147. package/src/utils/drizzle-graphql.ts +53 -14
  148. package/src/utils/loader-map.ts +5 -7
  149. package/src/utils/map-query.ts +20 -23
  150. package/src/utils/refs.ts +2 -2
  151. package/src/utils/selections.ts +8 -9
  152. package/src/utils/usage.ts +0 -2
@@ -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((ctx) => new Map<string, LoaderMappings>());
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
- Object.keys(value).forEach((field) => {
36
- const map = cache(ctx);
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) {
@@ -1,42 +1,41 @@
1
- /* eslint-disable no-continue */
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 { PothosValidationError } from '@pothos/core';
28
- import { type DrizzleFieldSelection } from '../types';
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>>>();
@@ -1,16 +1,15 @@
1
- /* eslint-disable no-param-reassign */
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 { PothosValidationError } from '@pothos/core';
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
- Object.entries(withSelection).forEach(([key, value]) => {
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) {
@@ -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