@drizzle-graphql-suite/schema 0.8.1 → 0.8.2
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/package.json +1 -1
- package/types.d.ts +146 -21
package/package.json
CHANGED
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
|
-
*
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
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
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
122
|
-
* - `
|
|
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;
|