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

feat!: support latest Prisma #164

Merged
merged 6 commits into from
Dec 6, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
matrix:
os: ['ubuntu-latest']
node-version: [16.x]
prisma-client-version: ['2.29', '2.30']
prisma-client-version: ['3.5']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
matrix:
os: ['ubuntu-latest']
node-version: [16.x]
prisma-client-version: ['2.29']
prisma-client-version: ['3.5']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"devDependencies": {
"@homer0/prettier-plugin-jsdoc": "^4.0.6",
"@prisma-labs/prettier-config": "0.1.0",
"@prisma/client": "3.6.0",
"@prisma/client": "^3.6.0",
"@prisma/sdk": "^3.6.0",
"@types/debug": "^4.1.7",
"@types/expand-tilde": "^2.0.0",
Expand Down Expand Up @@ -111,7 +111,7 @@
},
"prettier": "@prisma-labs/prettier-config",
"peerDependencies": {
"@prisma/client": "2.29.x || 2.30.x || 3.x",
"@prisma/client": "^3.5",
"nexus": "^1.0.0",
"ts-node": "^10.0.0"
},
Expand Down
29 changes: 14 additions & 15 deletions src/generator/models/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,29 @@ function renderNexusType(field: DMMF.Field, settings: Gentime.Settings): string
/**
* Map the fields type to a GraphQL type.
*
* @remarks The `settings` param type uses settings data instead of setset instance because this helper
* is used at runtime too where we don't have a Setset instane for gentime.
* @remarks The `settings` param type uses settings data instead of Setset instance because this helper
* is used at runtime too where we don't have a Setset instance for gentime.
*/
export function fieldTypeToGraphQLType(
field: DMMF.Field,
settings: Gentime.SettingsData
): LiteralUnion<StandardGraphQLScalarType, string> {
// TODO remove once PC is fixed https://prisma-company.slack.com/archives/C016KUHB1R6/p1638816683155000?thread_ts=1638563060.145800&cid=C016KUHB1R6
if (typeof field.type !== 'string') {
throw new TypeError(`field.type is supposed to always be a string.`)
}

switch (field.kind) {
case 'scalar': {
const typeName = field.type as PrismaScalarType

if (field.isId) {
if (field.type === 'String' || (field.type === 'Int' && settings.projectIdIntToGraphQL === 'ID')) {
return StandardGraphQLScalarTypes.ID
}
}

switch (typeName) {
const fieldType = field.type as PrismaScalarType

switch (fieldType) {
case 'String': {
return StandardGraphQLScalarTypes.String
}
Expand Down Expand Up @@ -342,24 +347,18 @@ export function fieldTypeToGraphQLType(
return 'Decimal'
}
default: {
return allCasesHandled(typeName)
return allCasesHandled(fieldType)
}
}
}
case 'enum': {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- But it does change the expression's type...
const typeName = field.type as string
return typeName
return field.type
}
case 'object': {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- But it does change the expression's type...
const typeName = field.type as string
return typeName
return field.type
}
case 'unsupported': {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- But it does change the expression's type...
const typeName = field.type as string
return typeName
return field.type
}
default:
allCasesHandled(field.kind)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
resolved "https://registry.npmjs.org/@prisma-labs/prettier-config/-/prettier-config-0.1.0.tgz"
integrity sha512-P0h2y+gnIxFP2HdsTYSYHWmabGBlxyVjnUepsrRe8gAF36mxOonGsbsQmKt/Q9H9CMjrSkFoDe5F5HLi2iW5/Q==

"@prisma/client@3.6.0":
"@prisma/client@^3.6.0":
version "3.6.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.6.0.tgz#68a60cd4c73a369b11f72e173e86fd6789939293"
integrity sha512-ycSGY9EZGROtje0iCNsgC5Zqi/ttX2sO7BNMYaLsUMiTlf3F69ZPH+08pRo0hrDfkZzyimXYqeXJlaoYDH1w7A==
Expand Down