amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

amplify mock api create mutation fails for model with @belongsTo directive

Open qndrey opened this issue 1 year ago • 6 comments

How did you install the Amplify CLI?

curl

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

v20.5.0

Amplify CLI Version

12.5.1

What operating system are you using?

Max (M1)

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

No manual changes made

Describe the bug

In schema.graphql we have two models like below

type Box @model @auth(rules: [{ allow: private }]) @searchable {
  id: ID!
  name: String!
  status: Status!
  events: [Event] @hasMany
}

type Event @model @auth(rules: [{ allow: private }]) @searchable {
  id: ID!
  name: String!
  box: Box @belongsTo
}

When I try to create Event with create even mutation the amplify mock local DynamoDB throws error and model is not being created.

Expected behavior

The local mock DynamoDB should allow create models with @belongsTo directive without id field when it is not required.

Reproduction steps

From the schema above we see that box is not required to create an Event.

Failure flow:

  • I mock api with a command amplify mock api - ok
  • I am creating a Box by using create box mutation - ok
  • I am creating Event without box (since it is not required) - fail

In terminal I see error:

Error while executing Local DynamoDB
{
    "version": "2018-05-29",
    "operation": "Query",
    "query": {
        "expression": "#partitionKey = :partitionValue",
        "expressionNames": {
            "#partitionKey": "id"
        },
        "expressionValues": {
            ":partitionValue": {
                "S": ""
            }
        }
    }
}
ValidationException: One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: id

Success flow:

  • I mock api with a command amplify mock api - ok
  • I am creating a Box by using create box mutation - ok
  • I am creating Even with box id - ok

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

qndrey avatar Oct 12 '23 12:10 qndrey