@vantreeseba/drizzle-graphql 7.3.0 → 7.4.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/README.md +62 -0
- package/dist/README.md +62 -0
- package/dist/index.cjs +180 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -23
- package/dist/index.d.ts +91 -23
- package/dist/index.js +178 -102
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,39 @@ Automatically create GraphQL schema or customizable schema config fields from Dr
|
|
|
85
85
|
})
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
+
## Naming the generated types and fields
|
|
89
|
+
|
|
90
|
+
By default every name comes from the table's key in the Drizzle schema: `tasks` gives type
|
|
91
|
+
`Tasks`, queries `tasks` / `tasksSingle`, mutations `createTasks` / `createTasksSingle`.
|
|
92
|
+
Most schemas use plural table keys and want singular type names, so that pairing is shipped
|
|
93
|
+
as a preset:
|
|
94
|
+
|
|
95
|
+
```Typescript
|
|
96
|
+
const { schema } = buildSchema(db, { typeNameMapper: 'singularize' })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`tasks` then gives type `Task`, queries `tasks` (list) and `task` (single), mutations
|
|
100
|
+
`createTasks` (array) and `createTask` (single), `updateTask`, `deleteTask`. Irregular
|
|
101
|
+
plurals go through `pluralize`, so `people` gives `Person` / `people` / `person` and
|
|
102
|
+
`addresses` gives `Address` rather than the `addresss` a naive suffix would produce. A table
|
|
103
|
+
key that is already singular is pluralized for the list side, and a capitalized key is
|
|
104
|
+
uncapitalized for the field side, so `tasks`, `task` and `Tasks` all land on the same names.
|
|
105
|
+
|
|
106
|
+
For anything else, pass your own function — it is asked per table and may return `undefined`
|
|
107
|
+
to leave that table with the default naming. The preset is exported as `singularizeMapper`
|
|
108
|
+
so it can be wrapped:
|
|
109
|
+
|
|
110
|
+
```Typescript
|
|
111
|
+
import { buildSchema, singularizeMapper } from 'drizzle-graphql'
|
|
112
|
+
|
|
113
|
+
const { schema } = buildSchema(db, {
|
|
114
|
+
typeNameMapper: (table) => (table === 'auditLog' ? undefined : singularizeMapper(table)),
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
With a mapper in play the singular/plural forms are what keep the list and single fields
|
|
119
|
+
apart, so `suffixes` may be empty on both sides. Without one, they must still differ.
|
|
120
|
+
|
|
88
121
|
## Choosing what gets generated
|
|
89
122
|
|
|
90
123
|
Every generated operation is on by default. `features` turns individual ones off, which
|
|
@@ -124,6 +157,35 @@ const { schema } = buildSchema(db, {
|
|
|
124
157
|
`mutations: false`
|
|
125
158
|
- List and single queries are always generated, so `Query` is never empty
|
|
126
159
|
|
|
160
|
+
### Per-table operations
|
|
161
|
+
|
|
162
|
+
The choice is rarely build-wide: a schema usually has a handful of tables that must not be
|
|
163
|
+
deleted through the API, a handful whose writes belong to a hand-written resolver that
|
|
164
|
+
enforces something, and a majority that want everything. Any flag can be a predicate
|
|
165
|
+
instead of a boolean, asked once per table with the table's key in the Drizzle schema:
|
|
166
|
+
|
|
167
|
+
```Typescript
|
|
168
|
+
const { schema } = buildSchema(db, {
|
|
169
|
+
features: {
|
|
170
|
+
delete: (table) => table !== 'auditLog',
|
|
171
|
+
update: (table) => !ownedByCustomResolver.has(table),
|
|
172
|
+
upsert: (table) => table === 'settings',
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- The table is still fully readable — this decides which operations it offers, not whether
|
|
178
|
+
it is in the schema at all. For that, use `exclude` below
|
|
179
|
+
- `nestedWrites` is the one flag that stays build-wide: its plans are computed once over
|
|
180
|
+
the whole relation graph, and a nested write reaches a second table by definition
|
|
181
|
+
- `Mutation` is omitted when *no* table generates a mutation, and kept when one still does
|
|
182
|
+
- Some operations are built out of others, and the generator knows which. A table that
|
|
183
|
+
asks for `upsert` while its `insert` or `update` is off — an upsert is a second write
|
|
184
|
+
path past the operation you turned off — warns on the console at build time, naming the
|
|
185
|
+
tables, rather than leaving that to be discovered later. So does asking for `updateMany`
|
|
186
|
+
without `update`, `groupBy` without `aggregates`, `countMutations` with neither plural
|
|
187
|
+
write, or `nestedWrites` alongside a table whose own writes are off
|
|
188
|
+
|
|
127
189
|
## Excluding tables and columns
|
|
128
190
|
|
|
129
191
|
`features` decides which *kinds* of operation exist. `exclude` decides which tables and
|
package/dist/README.md
CHANGED
|
@@ -85,6 +85,39 @@ Automatically create GraphQL schema or customizable schema config fields from Dr
|
|
|
85
85
|
})
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
+
## Naming the generated types and fields
|
|
89
|
+
|
|
90
|
+
By default every name comes from the table's key in the Drizzle schema: `tasks` gives type
|
|
91
|
+
`Tasks`, queries `tasks` / `tasksSingle`, mutations `createTasks` / `createTasksSingle`.
|
|
92
|
+
Most schemas use plural table keys and want singular type names, so that pairing is shipped
|
|
93
|
+
as a preset:
|
|
94
|
+
|
|
95
|
+
```Typescript
|
|
96
|
+
const { schema } = buildSchema(db, { typeNameMapper: 'singularize' })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`tasks` then gives type `Task`, queries `tasks` (list) and `task` (single), mutations
|
|
100
|
+
`createTasks` (array) and `createTask` (single), `updateTask`, `deleteTask`. Irregular
|
|
101
|
+
plurals go through `pluralize`, so `people` gives `Person` / `people` / `person` and
|
|
102
|
+
`addresses` gives `Address` rather than the `addresss` a naive suffix would produce. A table
|
|
103
|
+
key that is already singular is pluralized for the list side, and a capitalized key is
|
|
104
|
+
uncapitalized for the field side, so `tasks`, `task` and `Tasks` all land on the same names.
|
|
105
|
+
|
|
106
|
+
For anything else, pass your own function — it is asked per table and may return `undefined`
|
|
107
|
+
to leave that table with the default naming. The preset is exported as `singularizeMapper`
|
|
108
|
+
so it can be wrapped:
|
|
109
|
+
|
|
110
|
+
```Typescript
|
|
111
|
+
import { buildSchema, singularizeMapper } from 'drizzle-graphql'
|
|
112
|
+
|
|
113
|
+
const { schema } = buildSchema(db, {
|
|
114
|
+
typeNameMapper: (table) => (table === 'auditLog' ? undefined : singularizeMapper(table)),
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
With a mapper in play the singular/plural forms are what keep the list and single fields
|
|
119
|
+
apart, so `suffixes` may be empty on both sides. Without one, they must still differ.
|
|
120
|
+
|
|
88
121
|
## Choosing what gets generated
|
|
89
122
|
|
|
90
123
|
Every generated operation is on by default. `features` turns individual ones off, which
|
|
@@ -124,6 +157,35 @@ const { schema } = buildSchema(db, {
|
|
|
124
157
|
`mutations: false`
|
|
125
158
|
- List and single queries are always generated, so `Query` is never empty
|
|
126
159
|
|
|
160
|
+
### Per-table operations
|
|
161
|
+
|
|
162
|
+
The choice is rarely build-wide: a schema usually has a handful of tables that must not be
|
|
163
|
+
deleted through the API, a handful whose writes belong to a hand-written resolver that
|
|
164
|
+
enforces something, and a majority that want everything. Any flag can be a predicate
|
|
165
|
+
instead of a boolean, asked once per table with the table's key in the Drizzle schema:
|
|
166
|
+
|
|
167
|
+
```Typescript
|
|
168
|
+
const { schema } = buildSchema(db, {
|
|
169
|
+
features: {
|
|
170
|
+
delete: (table) => table !== 'auditLog',
|
|
171
|
+
update: (table) => !ownedByCustomResolver.has(table),
|
|
172
|
+
upsert: (table) => table === 'settings',
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- The table is still fully readable — this decides which operations it offers, not whether
|
|
178
|
+
it is in the schema at all. For that, use `exclude` below
|
|
179
|
+
- `nestedWrites` is the one flag that stays build-wide: its plans are computed once over
|
|
180
|
+
the whole relation graph, and a nested write reaches a second table by definition
|
|
181
|
+
- `Mutation` is omitted when *no* table generates a mutation, and kept when one still does
|
|
182
|
+
- Some operations are built out of others, and the generator knows which. A table that
|
|
183
|
+
asks for `upsert` while its `insert` or `update` is off — an upsert is a second write
|
|
184
|
+
path past the operation you turned off — warns on the console at build time, naming the
|
|
185
|
+
tables, rather than leaving that to be discovered later. So does asking for `updateMany`
|
|
186
|
+
without `update`, `groupBy` without `aggregates`, `countMutations` with neither plural
|
|
187
|
+
write, or `nestedWrites` alongside a table whose own writes are off
|
|
188
|
+
|
|
127
189
|
## Excluding tables and columns
|
|
128
190
|
|
|
129
191
|
`features` decides which *kinds* of operation exist. `exclude` decides which tables and
|