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(client): include enums into scalar select lists #16540

Merged
merged 1 commit into from
Dec 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/client/src/generation/TSClient/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ ${ifExtensions(() => {
export type ${getSelectName(model.name)}Scalar = {
${indent(
outputType.fields
.filter((field) => field.outputType.location === 'scalar')
.filter((field) => field.outputType.location === 'scalar' || field.outputType.location === 'enumTypes')
.map((f) => `${f.name}?: boolean`)
.join('\n'),
TAB_SIZE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineMatrix } from '../../_utils/defineMatrix'

export default defineMatrix(() => [
[
{
provider: 'postgresql',
},
{
provider: 'mysql',
},
{
provider: 'cockroachdb',
},
],
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { idForProvider } from '../../../_utils/idForProvider'
import testMatrix from '../_matrix'

export default testMatrix.setupSchema(({ provider }) => {
return /* Prisma */ `
generator client {
provider = "prisma-client-js"
previewFeatures = ["clientExtensions"]
}

datasource db {
provider = "${provider}"
url = env("DATABASE_URI_${provider}")
}

model User {
id ${idForProvider(provider)}
role UserRole
}

enum UserRole {
ADMIN
USER
}
`
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import testMatrix from './_matrix'
// @ts-ignore
import type { Prisma as PrismaNamespace, PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient
declare let Prisma: typeof PrismaNamespace

testMatrix.setupTestSuite(
() => {
test('allows to select enum field', async () => {
const user = await prisma.user.create({
data: {
role: 'ADMIN',
},
select: {
role: true,
},
})

expect(user).toEqual({ role: 'ADMIN' })
})
},
{
optOut: {
from: ['sqlite', 'mongodb', 'sqlserver'],
reason: 'No support for enums',
},
},
)