keystonejs / keystone

The superpowered headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
9.24k stars 1.16k forks source link

`calendarDay` won't accept default value #8783

Open beerdedfellow opened 1 year ago

beerdedfellow commented 1 year ago

Steps to reproduce

My apologies if this has been brought up. I've searched through the issues and found some that are related, but don't report this exactly. I have the following:

I have a Milestones schema/list with a field called due_date that is required. I am attempting to set a full-date string as the default value like the docs recommended:

            due_date: calendarDay({
                validation: { isRequired: true },
                defaultValue: '1970-01-01',
            }),

However, when I run keystone prisma migrate dev this produces the following error:

etDmmfError: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Error parsing attribute "@default": Parse error: "1970-01-01" is not a valid rfc3339 datetime string. (premature end of input)
  -->  schema.prisma:163
   | 
162 |   conversation Conversation[]       @relation("Conversation_milestone")
163 |   due_date     DateTime             @default("1970-01-01") @postgresql.Date
   | 

So I attempted to adjust the value to fit rfc3339 date-time format:

            due_date: calendarDay({
                validation: { isRequired: true },
                defaultValue: '1970-01-01T00:00:00.00Z',
            }),

I then receive the following error:

Error: The calendarDay field at Milestone.due_date specifies defaultValue: 1970-01-01T00:00:00.00Z but values must be provided as a full-date ISO8601 string such as 1970-01-01

Please describe what you expected to happen

calendarDay() field should accept ISO8601 full-date string format as a default value

Please add contextual information such as your node version (node -v), or the web browser you used

node ➜ /workspace/app (master) $ node -v
v18.16.0
    "dependencies": {
        "@graphql-tools/schema": "^10.0.0",
        "@keystone-6/auth": "^7.0.0",
        "@keystone-6/core": "^5.2.0",
        "@keystone-6/fields-document": "^8.0.0",
        "@prisma/client": "^4.14.1",
        "aws-cli": "^0.0.2",
        "typescript": "^5.0.4",
        "winston": "^3.8.2"
    },
    "devDependencies": {
        "@prisma/studio": "^0.484.0",
        "@types/node": "^20.2.5",
        "ts-node": "^10.9.1"
    },
    "os": [
        "linux",
        "darwin"
    ],
    "resolutions": {
        "next": "13.3.4"
marekryb commented 1 year ago

FWIW, this is broken on Prisma level.

Workaround would be to add some kind of setting to calendarDay to not use native database types for postgresql and mysql. Error does not happen for sqlite because it uses String in this case.

rivaslive commented 6 months ago

Same issue here!