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

(Gen 2) Issue using List when model has PK and SK. VariableTypeMismatch ModelIDKeyConditionInput #2452

Closed
Yogr opened this issue Apr 11, 2024 · 4 comments

Comments

@Yogr
Copy link

Yogr commented Apr 11, 2024

Environment information

System:
  OS: Windows 11 10.0.22621
  CPU: (16) x64 Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz
  Memory: 3.19 GB / 15.94 GB
Binaries:
  Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
  Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
  npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 0.13.0-beta.4
  @aws-amplify/backend-cli: 0.12.0-beta.4
  aws-amplify: 6.0.28
  aws-cdk: Not Found
  aws-cdk-lib: Not Found
  typescript: 5.3.2
AWS environment variables:
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables

Description

Error:

Validation error of type VariableTypeMismatch: Variable type 'ID' doesn't match expected type 'ModelIDKeyConditionInput' @ 'listChatMessages'"

I am trying to list all of the records stored in my ChatMessages table generated by Amplify gen 2 via:

ChatMessage: a
    .model({
      topicId: a.id().required(),
      messageId: a.id().required(),
      timestamp: a.datetime().required(),
      userId: a.string(),
      userName: a.string(),
      message: a.string().default(''),
    })
    .identifier(['topicId', 'messageId'])

I am invoking with the following code:

await client.models.ChatMessage.list()

This gives the error shown above. I can list other tables that I have that do not have a 2nd ID (which becomes the Sort key) and they work fine. However trying any table structure that has the 2 Keys will not work.

Here is what is in AppSync:

listChatMessages(
		topicId: ID,
		messageId: ModelIDKeyConditionInput,
		filter: ModelChatMessageFilterInput,
		limit: Int,
		nextToken: String,
		sortDirection: ModelSortDirection
	): ModelChatMessageConnection
input ModelIDKeyConditionInput {
	eq: ID
	le: ID
	lt: ID
	ge: ID
	gt: ID
	between: [ID]
	beginsWith: ID
}

I've been trying to manipulate the .list() function parameters to get past the error but can't seem to do so. .get() queries work fine when supplying both PK/SK IDs, create works as well.

Thanks!

@edwardfoyle
Copy link
Contributor

Hi @Yogr, I'm going to transfer this to the api repo. They should be able to help with this issue. However, in the meantime, I noticed you are using an older beta version of @aws-amplify/backend. I'd recommend updating to the latest beta release (currently 0.13.0-beta.16) to see if that helps.

@edwardfoyle edwardfoyle transferred this issue from aws-amplify/amplify-backend Apr 11, 2024
@Yogr
Copy link
Author

Yogr commented Apr 12, 2024

Ah, upgrading to the latest @beta version worked! thank you!

@AnilMaktala
Copy link
Member

Hi @Yogr, Thank you for confirming. I'm closing this issue as it has been resolved with the latest version.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants