-
Notifications
You must be signed in to change notification settings - Fork 820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to access createdAt and updatedAt? #401
Comments
Solution 2 will work but you will need to make the fields nullable or else all Create/Update inputs will require them even though they are being set on the server. |
Meaning not required, like this?
This works for me! I tried it the other way, |
One minor thing is as soon as you add createdAt to the model in the schema, then the transformer will add this to the CreateCategoryInput and UpdateCategoryInput, potentially allowing the client to pass a new createdAt and modify the createdAt date on an update call. |
These are good points. I think we should revisit this topic. This feature was added to make keeping track of timestamps easy but I agree that we should have the ability to tweak timestamp behavior. We are trying to make as few backwards incompatible changes as possible so what if we added a "timestamps" argument to # The default timestamps value would be
type Post @model(timestamps: {create: "createdAt", update: "updatedAt" }) {
id: ID!
} We would then remove those timestamp fields from the CreatePostInput and UpdatePostInput input objects. You could also turn timestamps off altogether type Post @model(timestamps: null) {
id: ID!
} And we would do nothing concerning timestamps. No input augmentation or otherwise? Would love to hear your thoughts. |
@mikeparisstuff Your solution would work for me as long as it would then be possible to query/filter by different timestamps. I think that's what you're proposing would be possible. |
Any update on a timeline for this? |
anyone? |
take a look at this issue issue#355@aws amplify docs |
@mikeparisstuff Is this implemented? |
Any updates on this? will it be possible to query |
bump :) |
@jordanranz @mikeparisstuff Is there any head way on this because the thought of having to manage this from the client seems problematic. Also tangental but similar is the idea of an audit log for objects? |
This is very confusing. In amplify docs, createdAt and updatedAt uses String 🤔🤔🤔🤔🤔 https://aws-amplify.github.io/docs/cli/graphql maybe use DateType(in appsync, AWSDateTime? ) related type shoud be better. https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html |
Would love to see a directive type approach @createdat or @updatedAt like Prisma introduced in April this year, seems a nice tradeoff but still easy to implement for what is a pretty common need for apps. https://www.prisma.io/blog/datamodel-v11-lrzqy1f56c90 |
Where did this land? |
Any updates? |
@hisham Would this be solved by adding a field-level auth directive so that the client wouldn't have the ability to modify?
|
You'd have to try it and look at the vtl resolver code to see how the auth logic is handled. Worth a try for sure. |
My question is why not just assume these things on behalf of us developers and build it in as the default case? Even with ledgers and other timestream databases it is still a common use case to query for the I'd much rather the core Amplify developers focus on the default developer case (this may or may not be considered opinionated) and take edge cases as feature requests, so that requests like OP don't drop through the cracks. Workarounds should not be required, they should be made the default case. IMO, the Amplify CLI should be a tool for enforcing best practices with AWS services anyway. Encouraging developers to conform to a sane default while providing escape hatches should be the default. |
This is one of those issues that makes me worry about using Amplify. I am commenting to keep the heat on. This is a really basic feature that should have been in from the start. |
where are we on this issue? I want this feature as well (to add my 2 cents) |
I agree with @murray-minito, please keep it up! |
Hi we've been investigating this issue the past couple weeks and are working on it. No ETA but we're actively looking into a fix. |
Expose createdAt and updatedAt automatically in the transformed schema. Added capability to change the createdAt and updatedAt field names using timestamps fix #401
Expose createdAt and updatedAt automatically in the transformed schema. Added capability to change the createdAt and updatedAt field names using timestamps fix aws-amplify#401
@yuth Thank you for this fix! I came across it today and I am trying it out. I have a type called I am now using However, when I try to list all Suggestions, I get an error because the old Suggestions in my DB do not have
When I try to update an old Suggestion, I get the error:
which makes sense because the documentation makes it seem like the newly named values still mostly function like createdAt and updatedAt. My question is how can I efficiently update the data I already have in production so that I can make use of the new @model directive? |
How about this functionality for RDS/Aurora? As of now, I'm creating the table fields manually. It'll be great to have this automatically taken care of by amplify. |
@yuth after updating the model with Backend api Schema type Clients
@model(timestamps: { createdAt: "createdOn", updatedAt: "updatedOn" })
@auth(
rules: [{ allow: groups, groups: ["companyAdmin"], operations: [create, read, update, delete] }]
) {
id: ID!
name: String!
email: String
tenantId: [ID!]
} This is what the datastore schema looks after running export const schema = {
"models": {
"Clients": {
"name": "Clients",
"fields": {
"id": {
"name": "id",
"isArray": false,
"type": "ID",
"isRequired": true,
"attributes": []
},
"name": {
"name": "name",
"isArray": false,
"type": "String",
"isRequired": true,
"attributes": []
},
"email": {
"name": "email",
"isArray": false,
"type": "String",
"isRequired": false,
"attributes": []
},
"tenantId": {
"name": "tenantId",
"isArray": true,
"type": "ID",
"isRequired": true,
"attributes": [],
"isArrayNullable": true
}
},
"syncable": true,
"pluralName": "Clients",
"attributes": [
{
"type": "model",
"properties": {
"timestamps": {
"createdAt": "createdOn",
"updatedAt": "updatedOn"
}
}
},
{
"type": "auth",
"properties": {
"rules": [
{
"groupClaim": "cognito:groups",
"provider": "userPools",
"allow": "groups",
"groups": [
"companyAdmin"
],
"operations": [
"create",
"read",
"update",
"delete"
]
}
]
}
}
]
}
},
"enums": {},
"nonModels": {},
"version": "af6a903d3f7a75d2403d0fc2dac75a7a"
}; |
@DevTGhosh I am having the exact same issue as well. |
A quick workaround is to add these fields to your type and you should have them accessible in data store schema. |
@patrickcze yeah as mentioned above just add the createdOn field to the model type Post
@model(timestamps: { createdAt: "createdOn", updatedAt: "updatedOn" }) {
id: ID!
title: String!
tags: [String!]!
createdOn: AWSDateTime!
updatedOn: AWSDateTime!
} @yuth Thanks for helping. |
This does not work with |
@yuth @DevTGhosh thanks for the reply, after making the same changes on your side have you seen errors like this?
|
@yuth I think this is important feedback. There are a lot of use cases where developers want to be able to query / display createdAt / updatedAt but do not want the responsibility of managing the timestamps themselves. This does not appear possible with the current |
FYI @sherl0cks the codegen team is tracking an issue for this bug here as we agree it should be something you can read from on the front end in your generated models. |
@kneekey23 much appreciated! |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
** Which Category is your question related to? **
amplify schema and DynamoDB
** What AWS Services are you utilizing? **
amplify-js, amplify-cli, AppSync, DynamoDb
** Provide additional details e.g. code snippets **
I've noticed that the Dynamo DB fields
createdAt
andupdatedAt
are automatically generated when Iamplify push
my graphql schema, but I can't figure out a way to query these fields. Is it possible, or should I add my own customcreatedAt
andupdatedAt
fields? Perhaps with different names? Just wondering what the best way to approach this is.Without date (
createdAt
andupdatedAt
automatically generated in DynamoDB):Solution 1 (add
createdOn
field, so not to override autocreatedAt
field):Solution 2 (override
createdAt
with custom field of same name):The text was updated successfully, but these errors were encountered: