Reputation: 59
I am using graphql
+ prisma
(in docker locally), nodejs
and postgresql
.
How can I make it add some fields like created/edited
date?
For example . I have this type:
type Post {
id: ID! @unique
title: String!
content: String!
published: Boolean! @default(value: "false")
author: User!
}
How can i add field like date. Make it equal to date the element created/updated?
Upvotes: 1
Views: 2840
Reputation:
Make this change in datamodel.prisma:
type Post {
id: ID! @unique
title: String!
content: String!
published: Boolean! @default(value: "false")
author: User!
updatedAt: DateTime!
createdAt: DateTime!
}
Make this change in schema.graphql:
updatedAt: String!
createdAt: String!
Upvotes: 2
Reputation: 200
There are 2 fields hidden by default on each type you create in Prisma, but they're always created and kept up to date in the background: createdAt: DateTime!
and updatedAt: DateTime!
. To expose them, simply add them to your type and try querying them, you should see that there's data already.
Also note that they can't be deleted, by removing them from your schema you hide them again.
Hope this helps.
Upvotes: 0