hirochachacha/graphql-auto-transformer

Using createdAt with @key doesn't work for updates

mnightingale opened this issue · 2 comments

When the @key directive is added and uses createdAt (or I assume updatedAt) as one of the fields it results in errors.

type Example
  @model
  @auth(rules: [{ allow: owner, operations: [create, read, update, delete] }])
  @key(name: "byOwner", fields: ["owner", "createdAt"], queryField: "examplesByOwner") {
  id: ID!
  owner: ID!
  createdAt: AWSDateTime! @auto
}

An attempt to do an update

When updating any part of the composite sort key for @key 'byOwner', you must provide all fields for the key. Missing key: 'createdAt'.

I figure it could be resolved with a custom resolver? But would I then have to handle setting the composite keys and would I lose the auth directive behaviour?

Thanks

Hey,
I just ran into the same problem.
Did you solve it and could you explain how?
I would really appreciate. Thanks!

I don't know if the behaviour was ever changed but as the error mentions createdAt is required, so I had to send the createdAt field within the create request.
I think an argument for createdAt/updatedAt being a special case could be made so their values get automatically populated when the server side value is generated.