diff --git a/.changeset/fix-baseitem-id.md b/.changeset/fix-baseitem-id.md new file mode 100644 index 00000000000..4e515b6ae9c --- /dev/null +++ b/.changeset/fix-baseitem-id.md @@ -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 diff --git a/packages/auth/src/gql/getInitFirstItemSchema.ts b/packages/auth/src/gql/getInitFirstItemSchema.ts index 5db6cfdb0e4..41334166e78 100644 --- a/packages/auth/src/gql/getInitFirstItemSchema.ts +++ b/packages/auth/src/gql/getInitFirstItemSchema.ts @@ -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, })) diff --git a/packages/core/src/types/next-fields.ts b/packages/core/src/types/next-fields.ts index fa3cadc1b8d..8e53b0679b4 100644 --- a/packages/core/src/types/next-fields.ts +++ b/packages/core/src/types/next-fields.ts @@ -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 } diff --git a/packages/core/src/types/type-info.ts b/packages/core/src/types/type-info.ts index ad3daa73c6b..c661fbe115a 100644 --- a/packages/core/src/types/type-info.ts +++ b/packages/core/src/types/type-info.ts @@ -12,7 +12,7 @@ export type BaseListTypeInfo = { create: GraphQLInput update: GraphQLInput where: GraphQLInput - uniqueWhere: { readonly id?: string | number | null } & GraphQLInput + uniqueWhere: { readonly id?: unknown } & GraphQLInput orderBy: Record } diff --git a/packages/fields-document/src/structure-graphql-input.ts b/packages/fields-document/src/structure-graphql-input.ts index 0b3de2630cf..87914e3fd55 100644 --- a/packages/fields-document/src/structure-graphql-input.ts +++ b/packages/fields-document/src/structure-graphql-input.ts @@ -340,7 +340,7 @@ export async function resolveRelateToManyForUpdateInput ( value: _UpdateValueManyType, context: KeystoneContext, foreignListKey: string, - prevVal: { id: string }[] + prevVal: BaseItem[] ) { if ( !Array.isArray(value.connect) && @@ -442,7 +442,7 @@ export async function checkUniqueItemExists ( throw missingItem(operation, uniqueInput) } - return { id: item.id.toString() } + return { id: item.id } } async function handleCreateAndUpdate ( @@ -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 (