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

Fix the type of id on type BaseItem, to be type unknown, not string #9054

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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/fix-baseitem-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
----
'@keystone-6/core': patch
----

Fixes the type of `id` on type `BaseItem`, to be type `unknown`, not `string` - `string` is not guaranteed
5 changes: 4 additions & 1 deletion packages/auth/src/gql/getInitFirstItemSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export function getInitFirstItemSchema ({
// the input value can't round-trip like the Upload scalar here is quite low)
const item = await sudoContext.db[listKey].createOne({ data: { ...data, ...itemData } })
const sessionToken = (await context.sessionStrategy.start({
data: { listKey, itemId: item.id.toString() },
data: {
listKey,
itemId: item.id
Copy link
Member

Choose a reason for hiding this comment

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

If you had a bigint id, this would fail since JSON.stringify with a bigint throws

},
context,
}))

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/types/next-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {

export { Decimal }

export type BaseItem = { id: { toString(): string }, [key: string]: unknown }
export type BaseItem = {
id: unknown,
[key: string]: unknown
}

export type ListGraphQLTypes = { types: GraphQLTypesForList }

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/type-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type BaseListTypeInfo<Session = any> = {
create: GraphQLInput
update: GraphQLInput
where: GraphQLInput
uniqueWhere: { readonly id?: string | number | null } & GraphQLInput
uniqueWhere: { readonly id?: unknown } & GraphQLInput
Copy link
Member

@emmatown emmatown Mar 6, 2024

Choose a reason for hiding this comment

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

string | number | null covers all that the input ID GraphQL type could be, what does widening this help?

orderBy: Record<string, 'asc' | 'desc' | null>
}

Expand Down
6 changes: 3 additions & 3 deletions packages/fields-document/src/structure-graphql-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export async function resolveRelateToManyForUpdateInput (
value: _UpdateValueManyType,
context: KeystoneContext,
foreignListKey: string,
prevVal: { id: string }[]
prevVal: BaseItem[]
) {
if (
!Array.isArray(value.connect) &&
Expand Down Expand Up @@ -442,7 +442,7 @@ export async function checkUniqueItemExists (
throw missingItem(operation, uniqueInput)
}

return { id: item.id.toString() }
return { id: item.id }
}

async function handleCreateAndUpdate (
Expand Down Expand Up @@ -470,7 +470,7 @@ async function resolveCreateMutation (value: any, context: KeystoneContext, fore
// it could change in the future
{} as GraphQLResolveInfo
)) as BaseItem
return { id: id.toString() }
return { id }
}

export function resolveRelateToOneForCreateInput (
Expand Down
Loading