The documentation for @default can be expanded to include default values for more types:
type Post {
title: String! @default(value: "New Post")
published: Boolean! @default(value: "false")
someNumber: Int! @default(value: "42")
}
Also see #1740.
How does it work with list types?
type User {
roles: [UserRole!]! @default(value: ["User"])
}
enum UserRole {
User
Admin
}
Edit: I found that the documentation states that list scalar fields don't work with @default, which is a pity. Is there a feature issue to allow this?
@marktani Looks like it doesn't work for Int too?
attempt: Int! @default(value: "0")
✖ You are making a field required, but there are already nodes that would violate that constraint.
@marktani Looks like it doesn't work for
Inttoo?attempt: Int! @default(value: "0")✖ You are making a field required, but there are already nodes that would violate that constraint.
I know this was a while back, but perhaps someone will associate the above response incorrectly.
the:
✖ You are making a field required, but there are already nodes that would violate that constraint.
Has nothing to do with the @default. Rather, the reason for that error is because there is already data stored Nodes on the database for that specific Model. By removing the ! would fix that error.
How does it work with list types?
type User { roles: [UserRole!]! @default(value: ["User"]) } enum UserRole { User Admin }Edit: I found that the documentation states that list scalar fields don't work with @default, which is a pity. Is there a feature issue to allow this?
Can you post such documentation?
Most helpful comment
How does it work with list types?
Edit: I found that the documentation states that list scalar fields don't work with @default, which is a pity. Is there a feature issue to allow this?