Skip to content

[Gen2] dynamodb error when having optional sortkeys #5050

Open
@hangoocn

Description

@hangoocn

Description

If making a field as sortKey in secondaryIndex and making the field optional, we are not able to submit a create request without specifying the value of this field.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. For any model, add secondary index like this:
Message: a
    .model({
      roomId: a.id().required(),
      room: a.belongsTo('Room', 'roomId'),
      createdAt: a.string(),
    }).secondaryIndexes(index => [index('roomId').sortKeys(['createdAt']).queryField('listByDate')])
  1. Then submit a request to create a message (without specify createAt value since it should be created by backend):
final newMessage = Message(room: room);
final request = ModelMutations.create(newMessage);
final response = await Amplify.API.mutate(request: request).response;
  1. Then it will show error One or more parameter values were invalid: Type mismatch for Index Key createdAt Expected, I noticed this is because createAt has a value null in request.variables['input'] instead of just ignoring it

What I want to do is just to sort messages by createAt date, this is one of the bug I found during the attempts. Not sure if it is the correct way.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.19.3

Amplify Flutter Version

2.0.0

Deployment Method

Amplify CLI

Schema

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    GraphQL APIIssues related to the API (GraphQL) Categoryfeature-requestA request for a new feature or an enhancement to an existing API or category.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions