Prisma1: Default value for DateTime field

Created on 26 Jan 2018  路  2Comments  路  Source: prisma/prisma1

What feature are you missing?

As I understand from the docs that as of now, it is not possible to set a default value for DateTime field via @default directive.

Currently, I am doing this at the application (graphql-yoga) level.

How could this feature look like in detail? Tradeoffs?

It should be possible to provide an "@default" value for DateTime.

type Post
{
  publishDate DateTime! @default(value: "<ISO Date>")
}

More thought needs to be given to handling things like setting NOW as the default DateTime value (and making that agnostic of the store).

I would love to hear the thoughts of Graphcool team on this and see if we can elaborate this proposal.

Thanks!

Most helpful comment

@marktani please do add it. Any concrete plans or that's far in the future?

All 2 comments

It's possible to set static default values for DateTime:

type Post
{
  publishDate DateTime! @default(value: "2018-01-26T06:16:12.123Z")
}

Dynamic default values are best set in the application layer, as you're already doing.
Over time, we might add special instructions for certain dynamic (like "now" for DateTime, or "max + 1" for Int).

I'm closing this for now, feel free to create a separate issue for dynamic default values.

@marktani please do add it. Any concrete plans or that's far in the future?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikolasburk picture nikolasburk  路  3Comments

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments

schickling picture schickling  路  3Comments

thomaswright picture thomaswright  路  3Comments