aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

AppSync: Custom @primaryKey Field Still Includes id in DynamoDB #2256

Open brianlenz opened 9 months ago

brianlenz commented 9 months ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

18.19.0

Amplify CLI Version

12.10.1

What operating system are you using?

macOS 14.3

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No.

Describe the bug

We have a simple model with a custom @primaryKey (stripping other fields for clarity), e.g.:

type File
@model
{
  filename: ID! @primaryKey
}

Everything gets created and looks good, but when creating a File through the mutation, the record inserted into DynamoDB includes both a filename and a separate id field. The id field should not be included. It's properly excluded from the GraphQL schema, but the id field shouldn't be inserted into the database.

Expected behavior

There is no id field in the database.

Reproduction steps

  1. Create a schema as described above.
  2. amplify push to create.
  3. Create an item through GraphQL.
  4. Inspect the raw data in DynamoDB.

Project Identifier

593c2cb7ef11977e0a84a81fe1b204c9

Log output

``` # Put your logs below this line ```

Additional information

I'm guessing the issue is in the generated resolver: MutationcreateFileinit0Function. Specifically, the resolver has this:

$util.qr($ctx.stash.defaultValues.put("id", $util.autoId()))

And I'm guessing that's what's causing the problem. This should be omitted when using a custom @primaryKey.

Before submitting, please confirm:

ykethan commented 9 months ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂.

brianlenz commented 9 months ago

Thanks, @ykethan!!

AnilMaktala commented 9 months ago

Hey @brianlenz , Thank you for reporting this. We are able to replicate the issue by following the description. Hence, we are marking this a bug for the team to evaluate further.

image image