Skip to content

Commit 18eed93

Browse files
authored
Move defaults to initConfig (#9027)
1 parent d828013 commit 18eed93

File tree

28 files changed

+423
-329
lines changed

28 files changed

+423
-329
lines changed

.changeset/add-number-id.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
----
2+
'@keystone-6/core': patch
3+
----
4+
5+
Use `idField` type of `{ kind: 'number', kind: 'Int' | 'BigInt' }` internally for singletons

design-system/packages/toast/src/Toast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { type ToastProps, type ToastPropsExact } from './types'
1515
// Provider
1616
// ------------------------------
1717

18-
export const ToastProvider = ({ children }: { children: ReactNode }) => {
18+
export function ToastProvider ({ children }: { children: ReactNode }) {
1919
const [toastStack, setToastStack] = useState<ToastPropsExact[]>([])
2020

2121
const context = useMemo(

design-system/website/pages/components/button.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { jsx, Stack } from '@keystone-ui/core'
55
import { Button, buttonToneValues, type ToneKey, buttonWeightValues } from '@keystone-ui/button'
66

77
import { Page } from '../../components/Page'
8-
import { toLabel } from '../../utils'
8+
import { capitalise } from '../../utils'
99

10-
const Variants = ({ tone }: { tone: ToneKey }) => {
11-
const toneLabel = toLabel(tone)
10+
function Variants ({ tone }: { tone: ToneKey }) {
11+
const toneLabel = capitalise(tone)
1212
return (
1313
<div>
1414
<h3>{toneLabel} Tone</h3>
1515
<Stack across gap="medium" align="center">
1616
{buttonWeightValues.map(weight => {
17-
const weightLabel = toLabel(weight)
17+
const weightLabel = capitalise(weight)
1818
return (
1919
<Button tone={tone} weight={weight} key={weight}>
2020
{toneLabel} {weightLabel}

design-system/website/pages/components/loading.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { jsx, Box, Stack } from '@keystone-ui/core'
66
import { LoadingDots, loadingToneValues } from '@keystone-ui/loading'
77

88
import { Page } from '../../components/Page'
9-
import { toLabel } from '../../utils'
9+
import { capitalise } from '../../utils'
1010

1111
export default function LoadingPage () {
1212
return (
@@ -19,19 +19,19 @@ export default function LoadingPage () {
1919
<h3>{tone}</h3>
2020
<Stack across gap="large">
2121
<LoadingDots
22-
label={`${toLabel(tone)} is loading`}
22+
label={`${capitalise(tone)} is loading`}
2323
key={tone}
2424
tone={tone}
2525
size="large"
2626
/>
2727
<LoadingDots
28-
label={`${toLabel(tone)} is loading`}
28+
label={`${capitalise(tone)} is loading`}
2929
key={tone}
3030
tone={tone}
3131
size="medium"
3232
/>
3333
<LoadingDots
34-
label={`${toLabel(tone)} is loading`}
34+
label={`${capitalise(tone)} is loading`}
3535
key={tone}
3636
tone={tone}
3737
size="small"

design-system/website/pages/components/notice.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { jsx } from '@keystone-ui/core'
55
import { Notice, noticeToneValues } from '@keystone-ui/notice'
66

77
import { Page } from '../../components/Page'
8-
import { toLabel, aAn } from '../../utils'
8+
import { capitalise, aAn } from '../../utils'
99

1010
export default function ButtonPage () {
1111
const actions = {
@@ -20,7 +20,7 @@ export default function ButtonPage () {
2020
<div css={{ maxWidth: 860 }}>
2121
{noticeToneValues.map(tone => (
2222
<Notice
23-
title={toLabel(tone)}
23+
title={capitalise(tone)}
2424
key={tone}
2525
tone={tone}
2626
css={{ marginBottom: 20 }}

design-system/website/pages/components/toast.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { jsx, Stack } from '@keystone-ui/core'
66
import { useToasts } from '@keystone-ui/toast'
77

88
import { Page } from '../../components/Page'
9+
import { capitalise } from '../../utils'
910

1011
export default function OptionsPage () {
1112
const { addToast } = useToasts()
@@ -16,7 +17,7 @@ export default function OptionsPage () {
1617
return (
1718
<Button
1819
onClick={() => {
19-
addToast({ title: `${titleCase(tone)} toast`, tone })
20+
addToast({ title: `${capitalise(tone)} toast`, tone })
2021
}}
2122
>
2223
Add {tone} toast
@@ -39,7 +40,3 @@ export default function OptionsPage () {
3940
</Page>
4041
)
4142
}
42-
43-
function titleCase (str: string) {
44-
return str.slice(0, 1).toUpperCase() + str.slice(1)
45-
}

design-system/website/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export const toLabel = (str: string) => str.slice(0, 1).toUpperCase() + str.slice(1)
1+
export function capitalise (s: string) {
2+
return s.charAt(0).toUpperCase() + s.slice(1)
3+
}
24

35
const VOWELS = ['a', 'e', 'i', 'o', 'u']
4-
export const aAn = (before: string) => `a${VOWELS.includes(before.charAt(0)) ? 'n' : ''}`
6+
export function aAn (before: string) {
7+
return `a${VOWELS.includes(before.charAt(0)) ? 'n' : ''}`
8+
}

examples/custom-id/schema.graphql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ type Order {
176176
id: ID!
177177
description: String
178178
assignedTo: Person
179+
options(where: OptionWhereInput! = {}, orderBy: [OptionOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OptionWhereUniqueInput): [Option!]
180+
optionsCount(where: OptionWhereInput! = {}): Int
179181
orderedAt: DateTime
180182
}
181183

@@ -190,9 +192,16 @@ input OrderWhereInput {
190192
id: IDFilter
191193
description: StringFilter
192194
assignedTo: PersonWhereInput
195+
options: OptionManyRelationFilter
193196
orderedAt: DateTimeNullableFilter
194197
}
195198

199+
input OptionManyRelationFilter {
200+
every: OptionWhereInput
201+
some: OptionWhereInput
202+
none: OptionWhereInput
203+
}
204+
196205
input OrderOrderByInput {
197206
id: OrderDirection
198207
description: OrderDirection
@@ -202,9 +211,17 @@ input OrderOrderByInput {
202211
input OrderUpdateInput {
203212
description: String
204213
assignedTo: PersonRelateToOneForUpdateInput
214+
options: OptionRelateToManyForUpdateInput
205215
orderedAt: DateTime
206216
}
207217

218+
input OptionRelateToManyForUpdateInput {
219+
disconnect: [OptionWhereUniqueInput!]
220+
set: [OptionWhereUniqueInput!]
221+
create: [OptionCreateInput!]
222+
connect: [OptionWhereUniqueInput!]
223+
}
224+
208225
input OrderUpdateArgs {
209226
where: OrderWhereUniqueInput!
210227
data: OrderUpdateInput!
@@ -213,9 +230,50 @@ input OrderUpdateArgs {
213230
input OrderCreateInput {
214231
description: String
215232
assignedTo: PersonRelateToOneForCreateInput
233+
options: OptionRelateToManyForCreateInput
216234
orderedAt: DateTime
217235
}
218236

237+
input OptionRelateToManyForCreateInput {
238+
create: [OptionCreateInput!]
239+
connect: [OptionWhereUniqueInput!]
240+
}
241+
242+
type Option {
243+
id: ID!
244+
description: String
245+
}
246+
247+
input OptionWhereUniqueInput {
248+
id: ID
249+
}
250+
251+
input OptionWhereInput {
252+
AND: [OptionWhereInput!]
253+
OR: [OptionWhereInput!]
254+
NOT: [OptionWhereInput!]
255+
id: IDFilter
256+
description: StringFilter
257+
}
258+
259+
input OptionOrderByInput {
260+
id: OrderDirection
261+
description: OrderDirection
262+
}
263+
264+
input OptionUpdateInput {
265+
description: String
266+
}
267+
268+
input OptionUpdateArgs {
269+
where: OptionWhereUniqueInput!
270+
data: OptionUpdateInput!
271+
}
272+
273+
input OptionCreateInput {
274+
description: String
275+
}
276+
219277
"""
220278
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
221279
"""
@@ -240,6 +298,12 @@ type Mutation {
240298
updateOrders(data: [OrderUpdateArgs!]!): [Order]
241299
deleteOrder(where: OrderWhereUniqueInput!): Order
242300
deleteOrders(where: [OrderWhereUniqueInput!]!): [Order]
301+
createOption(data: OptionCreateInput!): Option
302+
createOptions(data: [OptionCreateInput!]!): [Option]
303+
updateOption(where: OptionWhereUniqueInput!, data: OptionUpdateInput!): Option
304+
updateOptions(data: [OptionUpdateArgs!]!): [Option]
305+
deleteOption(where: OptionWhereUniqueInput!): Option
306+
deleteOptions(where: [OptionWhereUniqueInput!]!): [Option]
243307
}
244308

245309
type Query {
@@ -252,6 +316,9 @@ type Query {
252316
orders(where: OrderWhereInput! = {}, orderBy: [OrderOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OrderWhereUniqueInput): [Order!]
253317
order(where: OrderWhereUniqueInput!): Order
254318
ordersCount(where: OrderWhereInput! = {}): Int
319+
options(where: OptionWhereInput! = {}, orderBy: [OptionOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OptionWhereUniqueInput): [Option!]
320+
option(where: OptionWhereUniqueInput!): Option
321+
optionsCount(where: OptionWhereInput! = {}): Int
255322
keystone: KeystoneMeta!
256323
}
257324

examples/custom-id/schema.prisma

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ model Order {
3434
description String @default("")
3535
assignedTo Person? @relation("Order_assignedTo", fields: [assignedToId], references: [id])
3636
assignedToId String? @map("assignedTo")
37+
options Option[] @relation("Order_options")
3738
orderedAt DateTime?
3839
3940
@@index([assignedToId])
4041
}
42+
43+
model Option {
44+
id Int @id
45+
description String @default("")
46+
from_Order_options Order[] @relation("Order_options")
47+
}

examples/custom-id/schema.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const lists = {
3838
fields: {
3939
description: text({ validation: { isRequired: true } }),
4040
assignedTo: relationship({ ref: 'Person', many: false }),
41+
options: relationship({ ref: 'Option', many: true }),
4142
orderedAt: timestamp(),
4243
},
4344
hooks: {
@@ -48,4 +49,20 @@ export const lists = {
4849
},
4950
},
5051
}),
52+
Option: list({
53+
access: allowAll,
54+
db: {
55+
idField: { kind: 'number', type: 'Int' },
56+
},
57+
fields: {
58+
description: text({ validation: { isRequired: true } }),
59+
},
60+
hooks: {
61+
resolveInput: {
62+
create: async ({ listKey, operation, resolvedData }) => {
63+
return { ...resolvedData, id: 3 }
64+
},
65+
},
66+
},
67+
}),
5168
} satisfies Lists

0 commit comments

Comments
 (0)