-
Notifications
You must be signed in to change notification settings - Fork 823
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
using createdAt as a sortKey in @key directive results mandatory id and createdAt fields in CreateItemInput and CreateItem mutation in GraphQL Transform #1657
Comments
Also it is not limited to createdAt. Using |
I am in favor of this. A scenario where this is critical is a real time application where the date field must be controlled by one global system/server that sets the time. If the time is set by the application code, then there could be lapses and inconsistencies reflected in time of multiple events. If device A creates a mutation before device B, there is a strong possibility device B's time record in the database is earlier than the record of device A (This is due to the system time of each device). This is a BIG problem if device A and B are communicating. A solution in the mean time would be to send the records to a AWS lambda function to deal with the mutation, that is, the AWS lambda function handling the |
I did some research and a quick solution would be is to use an api to get a uniform time. If it is very important for the time timestamp to be consistent (which it should) you can use |
bump, just encountered this limitation. |
I've always had trouble retrieving Edit: confirmed access issue - #401 |
I've created https://github.com/hirochachacha/graphql-auto-transformer for solving these kinds of problems. |
Usage:
|
It turned out that amplify's import mechanism is broken. #3236 |
@hirochachacha Your transformer works again, since the issue above was resolved and merged about two weeks ago. However, when I use three field values, the composite key cannot not retrieve the autogenerated value. E.g., this model generates a correct looking Create mutation, however, when using it, it results in DB entries that look like this: As you can see, the "createdAt#sender" field is still trying to retrieve the createdAt value from the input, instead of using the auto-generated one. Is this something you could fix easily? I am using the latest amplify-cli version (4.20.0). |
@hanna-becker I've released 1.3.0 which might solve your problem. |
This fix is released in Amplify CLI v4.21.1 |
@hirochachacha Hi $util.qr($context.args.input.put("createdAt", $util.defaultIfNull($ctx.args.input.createdAt, util.time.nowISO8601()))) missing a '$' before util.time.nowISO8601 |
@TheUncharted Fixed. Thanks for pointing it out. BTW, If you find specific issues about the plugin, please report at https://github.com/hirochachacha/graphql-auto-transformer/issues instead. Thanks. |
I strongly believe that using @key directive on auto-generated fields should be supported by default. But it seems like after 2 years since this issue is created nothing has changed. Thank you @hirochachacha for providing the solution. |
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 |
In GraphQL Transform, transforming a schema that includes
@key
directive like:@key(fields: ["id", "createdAt"])
forces to make key fields non-nullable and that results with mandatoryid
andcreatedAt
fields inCreateItemInput
. SinceCreateItemInput
has these mandatory fields, it is a must to passid
andcreatedAt
tocreateItem
mutation. I wantcreatedAt
to be handled by automatically like mentioned here if it is possible: Timestamps for GraphQL/AppSync modelsExample:
Result:
Expected Result:
The text was updated successfully, but these errors were encountered: