Skip to content
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

Auto generate 'owner' value for update operations if primary key contain owner field #9

Open
yaquawa opened this issue May 9, 2021 · 0 comments · May be fixed by #11
Open

Auto generate 'owner' value for update operations if primary key contain owner field #9

yaquawa opened this issue May 9, 2021 · 0 comments · May be fixed by #11

Comments

@yaquawa
Copy link

yaquawa commented May 9, 2021

Hi, I'm really appreciate your work on this, without this plugin, I would have had to quit using Amplify...!!

I found an issue with a usecase that the primary key contain owner field.

For instance:

type Review
  @model
  @key(fields: ["owner", "serviceId"])
  @auth(rules: [ { allow: owner } ]) 
{
  id: ID!
  serviceId: ID!
  owner: String! @auto
  service: Service @connection(fields: ["serviceId"])
  rating: Int
  title: String
}

Now, updateReview wouldn't allow user to specify the owner field, which is fine, but, because the owner is the partition key of the Review table, DynamoDB requires the the owner field to update the item. So to make this work, we have to generate the value of 'owner'.

sure I can use @auto(updatable: true), so I can manually input the owner field, but it really should be generated automatically in this case.

I saw you have already auto generated the createdAt field, why not for the owner as well?

so the logic would be

  1. set ownerField default value to "owner".
  2. check if @auth directive contains ownerField argument, if it is, set ownerField to that value.
  3. check if fields argument of @key contains the value of ownerField.
  4. if step 3 is true, set $context.args.input.${ownerField} to the incoming request's identity.
@yaquawa yaquawa linked a pull request May 11, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant