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
81 stars 71 forks source link

DataStore autogenerated fields are not automatically populated during `amplify mock api` #1070

Open josefaidt opened 1 year ago

josefaidt commented 1 year ago

How did you install the Amplify CLI?

pnpm

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

18

Amplify CLI Version

10.5.1

What operating system are you using?

mac

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

n/a

Describe the bug

When mocking a GraphQL API that has Conflict Detection enabled, the fields used with DataStore such as _lastChangedAt are not automatically populated when creating records. Instead we are presented with an error:

{
  "data": {
    "createTodo": null
  },
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Todo._lastChangedAt.",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "createTodo",
        "_lastChangedAt"
      ]
    }
  ]
} 

image

Expected behavior

Fields are automatically created with their expected values in mock

Reproduction steps

  1. amplify init -y
  2. amplify add api > GraphQL > Enable conflict detection
  3. amplify mock api
  4. attempt to perform createTodo mutation with all fields in the selection set
  5. observe error
mutation CREATE_TODO {
  createTodo(input: {name: "hello todo"}) {
    _deleted
    _lastChangedAt
    _version
    createdAt
    description
    id
    name
    updatedAt
  }
}

Project Identifier

No response

Log output

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

Additional information

No response

Before submitting, please confirm:

AnilMaktala commented 1 year ago

I can reproduce the issue following steps mentioned above.

image