@drizzle-graphql-suite/schema 0.8.1 → 0.8.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +146 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drizzle-graphql-suite/schema",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "GraphQL schema builder with CRUD operations, relation filtering, and hooks from Drizzle ORM",
5
5
  "license": "MIT",
6
6
  "author": "https://github.com/dmythro",
package/types.d.ts CHANGED
@@ -65,31 +65,91 @@ export type TableOperations = {
65
65
  export type RelationPruneRule = false | 'leaf' | {
66
66
  only: string[];
67
67
  };
68
+ /**
69
+ * Configuration for both the GraphQL schema builder (server) and the
70
+ * type-safe client. Shared across `drizzle-graphql-suite/schema` and
71
+ * `drizzle-graphql-suite/client` so a single config object drives both
72
+ * the runtime schema and the inferred TypeScript types.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const config = {
77
+ * mutations: true,
78
+ * limitRelationDepth: 5,
79
+ * limitSelfRelationDepth: 2,
80
+ * suffixes: { list: 's', single: '' },
81
+ * tables: { exclude: ['session', 'account'] },
82
+ * pruneRelations: {
83
+ * 'asset.childAssets': false,
84
+ * 'override.asset': 'leaf',
85
+ * 'attribute.asset': { only: ['selectedVariant'] },
86
+ * },
87
+ * } as const satisfies BuildSchemaConfig
88
+ * ```
89
+ */
68
90
  export type BuildSchemaConfig = {
69
91
  /**
70
- * Set to `false` to omit mutations from the schema.
92
+ * Whether to generate GraphQL mutation operations (insert, update, delete).
93
+ * Set to `false` for a read-only schema.
94
+ * On the client side, controls whether mutation helpers are generated.
71
95
  * @default true
72
96
  */
73
97
  mutations?: boolean;
74
98
  /**
75
- * Limits depth of generated relation fields on queries.
76
- * Non-negative integer or undefined (no limit).
77
- * Set to 0 to omit relations altogether.
78
- * @default 3
99
+ * Maximum depth for expanding relation fields in the generated schema
100
+ * and in client-side filter types (`InferEntityFilters`).
101
+ *
102
+ * - **Server**: limits how many levels of nested relations appear in
103
+ * GraphQL object types. `undefined` means no limit.
104
+ * - **Client**: limits recursive relation filter type expansion to
105
+ * prevent TS7056 on circular schemas. Capped at 5.
106
+ *
107
+ * Set to `0` to omit relations altogether.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * // Allow up to 5 levels of nesting
112
+ * { limitRelationDepth: 5 }
113
+ * ```
114
+ * @default 3 (server) / 1 (client filter types)
79
115
  */
80
116
  limitRelationDepth?: number;
81
117
  /**
82
- * Max occurrences of the same table via direct self-relations in a type path.
83
- * - 1 = self-relation fields are omitted entirely (default)
84
- * - 2 = one level of self-relation expansion (e.g., item.parent exists but
85
- * the nested item has no parent/children fields)
86
- * Only applies to direct self-relations (source table === target table).
87
- * Cross-table paths that revisit a table are governed by limitRelationDepth.
118
+ * Max occurrences of the same table via direct self-relations in a
119
+ * single type path. Only applies to relations where source and target
120
+ * table are identical (e.g., `asset.parent asset`).
121
+ *
122
+ * - `1` = self-relation fields are omitted entirely
123
+ * - `2` = one level of self-relation expansion (the nested type has
124
+ * no further self-relation fields)
125
+ *
126
+ * Cross-table cycles that revisit a table are governed by
127
+ * `limitRelationDepth` instead.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * // category.parent → category (expanded), but nested category
132
+ * // won't have parent/children fields
133
+ * { limitSelfRelationDepth: 2 }
134
+ * ```
88
135
  * @default 1
89
136
  */
90
137
  limitSelfRelationDepth?: number;
91
138
  /**
92
- * Customizes query name suffixes.
139
+ * Customizes the suffixes appended to auto-generated query names.
140
+ *
141
+ * Given a table named `asset`:
142
+ * - List query: `asset` + `list` suffix → e.g. `"assets"` or `"assetList"`
143
+ * - Single query: `asset` + `single` suffix → e.g. `"asset"` or `"assetSingle"`
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * // "assets" / "asset" (pluralize list, no suffix for single)
148
+ * { suffixes: { list: 's', single: '' } }
149
+ *
150
+ * // "assetList" / "assetSingle" (explicit suffixes)
151
+ * { suffixes: { list: 'List', single: 'Single' } }
152
+ * ```
93
153
  * @default { list: '', single: 'Single' }
94
154
  */
95
155
  suffixes?: {
@@ -97,29 +157,94 @@ export type BuildSchemaConfig = {
97
157
  single?: string;
98
158
  };
99
159
  /**
100
- * Per-table hooks for queries and mutations.
101
- * Keys are table names as they appear in the Drizzle schema.
160
+ * Per-table lifecycle hooks for queries and mutations.
161
+ * Keys are table names as they appear in the Drizzle schema object.
162
+ *
163
+ * **Server-only** — hooks are executed during GraphQL resolution and have
164
+ * no effect on the client package. The client imports `BuildSchemaConfig`
165
+ * for type-level inference only (`limitRelationDepth`, `tables`, etc.)
166
+ * and ignores `hooks` entirely.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * {
171
+ * hooks: {
172
+ * asset: {
173
+ * query: { before: (ctx) => { ... } },
174
+ * insert: { after: (ctx, result) => { ... } },
175
+ * },
176
+ * },
177
+ * }
178
+ * ```
102
179
  */
103
180
  hooks?: HooksConfig;
104
181
  /**
105
- * Per-table configuration: exclude tables or limit operations.
182
+ * Per-table configuration: exclude tables entirely or limit which
183
+ * operations are generated per table.
184
+ *
106
185
  * Table names must match the keys in the Drizzle schema object.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * {
190
+ * tables: {
191
+ * // Remove auth tables from the GraphQL schema
192
+ * exclude: ['session', 'account', 'verification'],
193
+ * // Make 'auditLog' read-only
194
+ * config: { auditLog: { queries: true, mutations: false } },
195
+ * },
196
+ * }
197
+ * ```
107
198
  */
108
199
  tables?: {
109
200
  /** Tables to completely exclude (no types, no operations, relations to them skipped). */
110
- exclude?: string[];
201
+ exclude?: readonly string[];
111
202
  /** Per-table operation overrides. Tables not listed get default behavior. */
112
203
  config?: Record<string, TableOperations>;
113
204
  };
114
205
  /**
115
- * Fine-grained per-relation pruning rules.
116
- * Keys are `tableName.relationName` (e.g., `'asset.childAssets': false`).
206
+ * Fine-grained per-relation pruning rules that control how each
207
+ * relation expands in the generated schema.
208
+ *
209
+ * **Server-only** — pruning shapes the generated GraphQL schema.
210
+ * The client builds queries from the schema descriptor, which already
211
+ * reflects pruning (pruned relations are absent), so the client
212
+ * cannot generate queries for pruned fields.
213
+ *
214
+ * Keys use `tableName.relationName` format. Values:
215
+ * - `false` — relation field is omitted entirely from the parent type
216
+ * - `'leaf'` — relation expands with scalar columns only (no nested relations)
217
+ * - `{ only: string[] }` — relation expands with only the listed child relations
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * {
222
+ * pruneRelations: {
223
+ * // Remove back-reference completely
224
+ * 'assetType.assets': false,
225
+ * // Show override.asset but don't expand its relations
226
+ * 'override.asset': 'leaf',
227
+ * // Only keep selectedVariant on attribute.asset
228
+ * 'attribute.asset': { only: ['selectedVariant'] },
229
+ * },
230
+ * }
231
+ * ```
117
232
  */
118
233
  pruneRelations?: Record<string, RelationPruneRule>;
119
234
  /**
120
- * Enable debug logging for schema diagnostics.
121
- * - `true`: logs SDL byte size and type count
122
- * - `{ schemaSize?: boolean; relationTree?: boolean }`: selective logging
235
+ * Enable debug logging for schema diagnostics (server-side only).
236
+ *
237
+ * - `true` logs SDL byte size and type count
238
+ * - `{ schemaSize?: boolean; relationTree?: boolean }` — selective logging
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * // Log everything
243
+ * { debug: true }
244
+ *
245
+ * // Only log the relation expansion tree
246
+ * { debug: { relationTree: true } }
247
+ * ```
123
248
  */
124
249
  debug?: boolean | {
125
250
  schemaSize?: boolean;