Skip to content

Commit

Permalink
change id type for BaseItem to be unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jun 26, 2024
1 parent 3c413cd commit ad7646d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
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
},
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
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

0 comments on commit ad7646d

Please sign in to comment.