Schema and default values - eg, creation date


I’d like to be able to store the created time and date for a Graphql type, ideally with a default value, in the schema.

The goal, too, is to avoid the client application having to send the created value, which could also be an inaccurate value.

In Sql this can be achieved using something similar to created TIMESTAMP DEFAULT NOW().

Is it possible to do something similar in Graphql?

They have not added this feature yet (very important IMHO), though they hinted at sometime this year…

In the meantime, the best route is to use a hook with something like addPostWebhook. Keep in mind, for the moment it only supports post-hooks (hopefully pre-hooks one day). This should be up on Cloud DGraph by the end of the week with 21.03:

Basically, you would just add a createdAt value after the rest of the field is created, and you could add updatePostWebhook with updatedAt value for after a field is updated. If someone passed in a date, you could reject the call, or simply replace the value with the correct date and not worry about it.


Thank you J

The Lambda webhooks does look like a solution, though it is a lot more work than simply setting a default value. That being said, the web hooks do offer much more capabilities.

Thank you for your prompt and helpful response!

1 Like

The @defualt derective is avairable in v21.12