@model(queries: null, subscriptions: null)
@key(name: "bySender", fields: ["senderId"])
@key(name: "byDate", fields: ["channelId", "createdAt"], queryField: "getMessagesByDate")
@key(name: "byHasBeenRead", fields: ["hasBeenReadByIds"])
@auth(
rules: [
{ allow: groups, groups: ["externalUser"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["agent"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["engineer"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["superAdmin"], operations: [read, create, update, delete] }
]
) {
id: ID!
channelId: ID!
senderId: ID!
channel: Channel @connection(fields: ["channelId"])
sender: User @connection(fields: ["senderId"])
createdAt: AWSDateTime!
text: String
hasBeenReadByIds: [ID!]
}```
I try to update the hasBeenReadByIds as shown below. Where readByUsers is an array of strings.
try {
(await API.graphql(
graphqlOperation(updateMessage, {
input: {
id: message.id,
hasBeenReadByIds: readByUsers,
},
}),
))
} catch (error) {
console.log(`error --- `, error, readByUsers);
}
And i get the following error...
{
"data": {
"updateMessage": null
},
"errors": [
{
"path": [
"updateMessage"
],
"data": null,
"errorType": "DynamoDB:DynamoDbException",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "One or more parameter values were invalid: Type mismatch for Index Key hasBeenReadByIds Expected: S Actual: L IndexName: byHasBeenRead (Service: DynamoDb, Status Code: 400, Request ID: )"
}
]
}
I have tried passing every string format that I can think of. ["xxxx", "yyyy"], "['xxxx', 'yyyy']", "xxxx,yyyy", [{"xxxx"},{ "yyyy"}], "L": [{"S": "xxx"}]... And many more variations of that kind of thing.
If i edit the field directly in dynamo, it will take pretty much anything that is a string. But not an array. But regardless of what string i put in, i get the following when use the syncMessages query.
[
{
"path": [
"syncMessages",
"items",
0,
"hasBeenReadByIds"
],
"locations": null,
"message": "Can't resolve value (/syncMessages/items[0]/hasBeenReadByIds) : type mismatch error, expected type LIST"
}
]
I also tried all of this with hasBeenReadByIds: [ID!] as hasBeenReadByIds: [String!].
### Expected behavior
I would expect to be able to pass an array of strings in the updateMessage graphql variables.
### Reproduction steps
1. Add the following object to your schema. I am assuming the sender and user can be removed so you don't have to create those types.
type Message
@model(queries: null, subscriptions: null)
@key(name: "bySender", fields: ["senderId"])
@key(name: "byDate", fields: ["channelId", "createdAt"], queryField: "getMessagesByDate")
@key(name: "byHasBeenRead", fields: ["hasBeenReadByIds"])
@auth(
rules: [
{ allow: groups, groups: ["externalUser"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["agent"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["engineer"], operations: [read, create, update, delete] }
{ allow: groups, groups: ["superAdmin"], operations: [read, create, update, delete] }
]
) {
id: ID!
channelId: ID!
senderId: ID!
channel: Channel @connection(fields: ["channelId"])
sender: User @connection(fields: ["senderId"])
createdAt: AWSDateTime!
text: String
hasBeenReadByIds: [ID!]
}
2. Try to use the updateMessage graphql mutation to set hasBeenReadByIds.
### Code Snippet
```javascript
// Put your code below this line.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
Describe the bug
I have the message type, shown below.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
Chrome
Mobile Browser Version
No response
Additional information and screenshots
No response