Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move defaults to initConfig #9027

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-number-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
----
'@keystone-6/core': patch
----

Use `idField` type of `{ kind: 'number', kind: 'Int' | 'BigInt' }` internally for singletons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just have static value for this?

may be global-config or settings or just add to list config applicable when isSingleton is true;

Copy link
Member Author

@dcousens dcousens Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gautamsi I didn't see a reason why we should prevent developers from having this kind of identifier type available for their own usage, while additionally allowing me me to remove isSingleton logic from the id-field

2 changes: 1 addition & 1 deletion design-system/packages/toast/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { type ToastProps, type ToastPropsExact } from './types'
// Provider
// ------------------------------

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

const context = useMemo(
Expand Down
8 changes: 4 additions & 4 deletions design-system/website/pages/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { jsx, Stack } from '@keystone-ui/core'
import { Button, buttonToneValues, type ToneKey, buttonWeightValues } from '@keystone-ui/button'

import { Page } from '../../components/Page'
import { toLabel } from '../../utils'
import { capitalise } from '../../utils'

const Variants = ({ tone }: { tone: ToneKey }) => {
const toneLabel = toLabel(tone)
function Variants ({ tone }: { tone: ToneKey }) {
const toneLabel = capitalise(tone)
return (
<div>
<h3>{toneLabel} Tone</h3>
<Stack across gap="medium" align="center">
{buttonWeightValues.map(weight => {
const weightLabel = toLabel(weight)
const weightLabel = capitalise(weight)
return (
<Button tone={tone} weight={weight} key={weight}>
{toneLabel} {weightLabel}
Expand Down
8 changes: 4 additions & 4 deletions design-system/website/pages/components/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jsx, Box, Stack } from '@keystone-ui/core'
import { LoadingDots, loadingToneValues } from '@keystone-ui/loading'

import { Page } from '../../components/Page'
import { toLabel } from '../../utils'
import { capitalise } from '../../utils'

export default function LoadingPage () {
return (
Expand All @@ -19,19 +19,19 @@ export default function LoadingPage () {
<h3>{tone}</h3>
<Stack across gap="large">
<LoadingDots
label={`${toLabel(tone)} is loading`}
label={`${capitalise(tone)} is loading`}
key={tone}
tone={tone}
size="large"
/>
<LoadingDots
label={`${toLabel(tone)} is loading`}
label={`${capitalise(tone)} is loading`}
key={tone}
tone={tone}
size="medium"
/>
<LoadingDots
label={`${toLabel(tone)} is loading`}
label={`${capitalise(tone)} is loading`}
key={tone}
tone={tone}
size="small"
Expand Down
4 changes: 2 additions & 2 deletions design-system/website/pages/components/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { jsx } from '@keystone-ui/core'
import { Notice, noticeToneValues } from '@keystone-ui/notice'

import { Page } from '../../components/Page'
import { toLabel, aAn } from '../../utils'
import { capitalise, aAn } from '../../utils'

export default function ButtonPage () {
const actions = {
Expand All @@ -20,7 +20,7 @@ export default function ButtonPage () {
<div css={{ maxWidth: 860 }}>
{noticeToneValues.map(tone => (
<Notice
title={toLabel(tone)}
title={capitalise(tone)}
key={tone}
tone={tone}
css={{ marginBottom: 20 }}
Expand Down
7 changes: 2 additions & 5 deletions design-system/website/pages/components/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { jsx, Stack } from '@keystone-ui/core'
import { useToasts } from '@keystone-ui/toast'

import { Page } from '../../components/Page'
import { capitalise } from '../../utils'

export default function OptionsPage () {
const { addToast } = useToasts()
Expand All @@ -16,7 +17,7 @@ export default function OptionsPage () {
return (
<Button
onClick={() => {
addToast({ title: `${titleCase(tone)} toast`, tone })
addToast({ title: `${capitalise(tone)} toast`, tone })
}}
>
Add {tone} toast
Expand All @@ -39,7 +40,3 @@ export default function OptionsPage () {
</Page>
)
}

function titleCase (str: string) {
return str.slice(0, 1).toUpperCase() + str.slice(1)
}
8 changes: 6 additions & 2 deletions design-system/website/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const toLabel = (str: string) => str.slice(0, 1).toUpperCase() + str.slice(1)
export function capitalise (s: string) {
return s.charAt(0).toUpperCase() + s.slice(1)
}

const VOWELS = ['a', 'e', 'i', 'o', 'u']
export const aAn = (before: string) => `a${VOWELS.includes(before.charAt(0)) ? 'n' : ''}`
export function aAn (before: string) {
return `a${VOWELS.includes(before.charAt(0)) ? 'n' : ''}`
}
67 changes: 67 additions & 0 deletions examples/custom-id/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ type Order {
id: ID!
description: String
assignedTo: Person
options(where: OptionWhereInput! = {}, orderBy: [OptionOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OptionWhereUniqueInput): [Option!]
optionsCount(where: OptionWhereInput! = {}): Int
orderedAt: DateTime
}

Expand All @@ -190,9 +192,16 @@ input OrderWhereInput {
id: IDFilter
description: StringFilter
assignedTo: PersonWhereInput
options: OptionManyRelationFilter
orderedAt: DateTimeNullableFilter
}

input OptionManyRelationFilter {
every: OptionWhereInput
some: OptionWhereInput
none: OptionWhereInput
}

input OrderOrderByInput {
id: OrderDirection
description: OrderDirection
Expand All @@ -202,9 +211,17 @@ input OrderOrderByInput {
input OrderUpdateInput {
description: String
assignedTo: PersonRelateToOneForUpdateInput
options: OptionRelateToManyForUpdateInput
orderedAt: DateTime
}

input OptionRelateToManyForUpdateInput {
disconnect: [OptionWhereUniqueInput!]
set: [OptionWhereUniqueInput!]
create: [OptionCreateInput!]
connect: [OptionWhereUniqueInput!]
}

input OrderUpdateArgs {
where: OrderWhereUniqueInput!
data: OrderUpdateInput!
Expand All @@ -213,9 +230,50 @@ input OrderUpdateArgs {
input OrderCreateInput {
description: String
assignedTo: PersonRelateToOneForCreateInput
options: OptionRelateToManyForCreateInput
orderedAt: DateTime
}

input OptionRelateToManyForCreateInput {
create: [OptionCreateInput!]
connect: [OptionWhereUniqueInput!]
}

type Option {
id: ID!
description: String
}

input OptionWhereUniqueInput {
id: ID
}

input OptionWhereInput {
AND: [OptionWhereInput!]
OR: [OptionWhereInput!]
NOT: [OptionWhereInput!]
id: IDFilter
description: StringFilter
}

input OptionOrderByInput {
id: OrderDirection
description: OrderDirection
}

input OptionUpdateInput {
description: String
}

input OptionUpdateArgs {
where: OptionWhereUniqueInput!
data: OptionUpdateInput!
}

input OptionCreateInput {
description: String
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
Expand All @@ -240,6 +298,12 @@ type Mutation {
updateOrders(data: [OrderUpdateArgs!]!): [Order]
deleteOrder(where: OrderWhereUniqueInput!): Order
deleteOrders(where: [OrderWhereUniqueInput!]!): [Order]
createOption(data: OptionCreateInput!): Option
createOptions(data: [OptionCreateInput!]!): [Option]
updateOption(where: OptionWhereUniqueInput!, data: OptionUpdateInput!): Option
updateOptions(data: [OptionUpdateArgs!]!): [Option]
deleteOption(where: OptionWhereUniqueInput!): Option
deleteOptions(where: [OptionWhereUniqueInput!]!): [Option]
}

type Query {
Expand All @@ -252,6 +316,9 @@ type Query {
orders(where: OrderWhereInput! = {}, orderBy: [OrderOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OrderWhereUniqueInput): [Order!]
order(where: OrderWhereUniqueInput!): Order
ordersCount(where: OrderWhereInput! = {}): Int
options(where: OptionWhereInput! = {}, orderBy: [OptionOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: OptionWhereUniqueInput): [Option!]
option(where: OptionWhereUniqueInput!): Option
optionsCount(where: OptionWhereInput! = {}): Int
keystone: KeystoneMeta!
}

Expand Down
7 changes: 7 additions & 0 deletions examples/custom-id/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ model Order {
description String @default("")
assignedTo Person? @relation("Order_assignedTo", fields: [assignedToId], references: [id])
assignedToId String? @map("assignedTo")
options Option[] @relation("Order_options")
orderedAt DateTime?

@@index([assignedToId])
}

model Option {
id Int @id
description String @default("")
from_Order_options Order[] @relation("Order_options")
}
17 changes: 17 additions & 0 deletions examples/custom-id/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const lists = {
fields: {
description: text({ validation: { isRequired: true } }),
assignedTo: relationship({ ref: 'Person', many: false }),
options: relationship({ ref: 'Option', many: true }),
orderedAt: timestamp(),
},
hooks: {
Expand All @@ -48,4 +49,20 @@ export const lists = {
},
},
}),
Option: list({
access: allowAll,
db: {
idField: { kind: 'number', type: 'Int' },
},
fields: {
description: text({ validation: { isRequired: true } }),
},
hooks: {
resolveInput: {
create: async ({ listKey, operation, resolvedData }) => {
return { ...resolvedData, id: 3 }
},
},
},
}),
} satisfies Lists
20 changes: 7 additions & 13 deletions packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createRequire } from 'node:module'
import { printSchema, GraphQLSchema } from 'graphql'
import { getGenerators, formatSchema } from '@prisma/internals'
import type { KeystoneConfig } from './types'
import { printGeneratedTypes } from './lib/schema-type-printer'
import { printGeneratedTypes } from './lib/typescript-schema-printer'
Copy link
Member Author

@dcousens dcousens Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to align with prisma-schema-printer.ts, I don't know why it was .tsx

import { ExitError } from './scripts/utils'
import { initialiseLists } from './lib/core/initialise-lists'
import { printPrismaSchema } from './lib/core/prisma-schema-printer'
Expand All @@ -21,15 +21,7 @@ export function getFormattedGraphQLSchema (schema: string) {

export async function getCommittedArtifacts (config: KeystoneConfig, graphQLSchema: GraphQLSchema) {
const lists = initialiseLists(config)
const prismaSchema = printPrismaSchema(
lists,
config.db.prismaClientPath,
config.db.provider,
config.db.prismaPreviewFeatures,
config.db.additionalPrismaDatasourceProperties,
config.db.extendPrismaSchema
)

const prismaSchema = printPrismaSchema(config, lists)
return {
graphql: getFormattedGraphQLSchema(printSchema(graphQLSchema)),
prisma: await formatPrismaSchema(prismaSchema),
Expand Down Expand Up @@ -88,9 +80,11 @@ function posixify (s: string) {
}

export function getSystemPaths (cwd: string, config: KeystoneConfig) {
const prismaClientPath = config.db.prismaClientPath
? path.join(cwd, config.db.prismaClientPath)
: null
const prismaClientPath = config.db.prismaClientPath === '@prisma/client'
? null
: config.db.prismaClientPath
? path.join(cwd, config.db.prismaClientPath)
: null

const builtTypesPath = config.types?.path
? path.join(cwd, config.types.path) // TODO: enforce initConfig before getSystemPaths
Expand Down
55 changes: 0 additions & 55 deletions packages/core/src/lib/config.ts

This file was deleted.

Loading