aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.13k forks source link

One or more parameter values were invalid: Type mismatch #10130

Closed LeoReubelt closed 2 years ago

LeoReubelt commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: macOS 12.3.1 CPU: (8) x64 Apple M1 Memory: 36.45 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.17.2 - ~/.nvm/versions/node/v14.17.2/bin/node Yarn: 1.22.11 - /usr/local/bin/yarn npm: 8.12.1 - ~/.nvm/versions/node/v14.17.2/bin/npm Browsers: Chrome: 103.0.5060.134 Safari: 15.4 npmPackages: @ampproject/toolbox-optimizer: undefined () @aws-amplify/analytics: ^5.2.6 => 5.2.9 @aws-amplify/api: ^4.0.39 => 4.0.42 @aws-amplify/auth: ^4.5.3 => 4.5.6 @aws-amplify/cache: ^4.0.41 => 4.0.44 @aws-amplify/core: ^4.5.3 => 4.5.6 @aws-amplify/datastore: ^3.3.3 => 3.11.3 @aws-amplify/interactions: ^4.0.39 => 4.0.42 @aws-amplify/pubsub: ^4.4.0 => 4.4.3 @aws-amplify/storage: ^4.4.22 => 4.4.25 @aws-amplify/ui: ^3.8.2 => 3.9.2 (2.0.5) @aws-amplify/ui-react: ^2.19.0 => 2.19.0 @aws-amplify/ui-react-internal: undefined () @aws-amplify/ui-react-legacy: undefined () @aws-amplify/xr: ^3.0.39 => 3.0.42 @babel/core: undefined () @babel/runtime: 7.15.4 @craftjs/core: ^0.2.0-beta.2 => 0.2.0-beta.5 @hapi/accept: undefined () @napi-rs/triples: undefined () @next/react-dev-overlay: undefined () @next/react-refresh-utils: 12.1.6 @peculiar/webcrypto: undefined () @react-hook/debounce: ^4.0.0 => 4.0.0 @react-three/drei: ^8.20.2 => 8.20.2 @react-three/fiber: ^7.0.0 => 7.0.29 @types/debounce: ^1.2.0 => 1.2.1 @types/deep-equal: ^1.0.1 => 1.0.1 @types/flickity: ^2.2.6 => 2.2.6 @types/lodash: ^4.14.182 => 4.14.182 @types/node: ^17.0.29 => 17.0.40 @types/papaparse: ^5.3.2 => 5.3.2 @types/react: 17.0.19 => 17.0.19 @types/react-beautiful-dnd: ^13.1.1 => 13.1.2 @types/react-color: ^3.0.5 => 3.0.6 @types/react-copy-to-clipboard: ^5.0.1 => 5.0.2 @types/react-dom: 17.0.9 => 17.0.9 @types/react-window: ^1.8.5 => 1.8.5 @types/three: ^0.139.0 => 0.139.0 @types/throttle-debounce: ^5.0.0 => 5.0.0 @types/uuid: ^8.3.1 => 8.3.4 @typescript-eslint/eslint-plugin: 4.29.3 => 4.29.3 (5.27.1) @typescript-eslint/parser: 4.29.3 => 4.29.3 (5.27.1) @vercel/nft: undefined () abort-controller: undefined () acorn: undefined () agora-rtc-sdk-ng: ^4.6.3 => 4.11.1 amphtml-validator: undefined () antd: 4.16.13 => 4.16.13 antd-img-crop: ^4.1.0 => 4.2.3 arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () aws-amplify: ^4.3.24 => 4.3.24 aws-amplify-react: ^5.0.11 => 5.1.9 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () chalk: undefined () ci-info: undefined () classnames: ^2.3.1 => 2.3.1 cli-select: undefined () comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () cssnano-simple: undefined () date-fns: ^2.28.0 => 2.28.0 debounce: ^1.2.1 => 1.2.1 debug: undefined () deep-copy-ts: ^0.5.4 => 0.5.4 deep-equal: ^2.0.5 => 2.0.5 devalue: undefined () domain-browser: undefined () eslint: 7.32.0 => 7.32.0 (8.17.0) eslint-config-next: ^11.1.0 => 11.1.4 eslint-config-prettier: 8.3.0 => 8.3.0 eslint-import-resolver-typescript: 2.4.0 => 2.4.0 eslint-plugin-import: 2.24.2 => 2.24.2 (2.26.0) eslint-plugin-jsx-a11y: 6.4.1 => 6.4.1 (6.5.1) eslint-plugin-prettier: 3.4.1 => 3.4.1 eslint-plugin-react: 7.25.0 => 7.25.0 (7.30.0) eslint-plugin-react-hooks: 4.2.0 => 4.2.0 (4.5.0) eslint-plugin-simple-import-sort: ^7.0.0 => 7.0.0 etag: undefined () events: undefined () find-cache-dir: undefined () find-up: undefined () flickity: ^2.2.1 => 2.3.0 formdata-node: undefined () fresh: undefined () get-orientation: undefined () glob: undefined () gzip-size: undefined () http-proxy: undefined () https-browserify: undefined () husky: ^7.0.2 => 7.0.4 icss-utils: undefined () ignore-loader: undefined () image-size: undefined () immer: ^9.0.12 => 9.0.14 (9.0.6) is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () jotai: ^1.6.5 => 1.7.1 json5: undefined () jsonwebtoken: undefined () jszip: ^3.10.0 => 3.10.0 (2.5.0) lint-staged: 11.1.2 => 11.1.2 loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () lzutf8: ^0.6.0 => 0.6.2 micromatch: undefined () mini-css-extract-plugin: undefined () moment: ^2.29.1 => 2.29.3 nanoid: undefined () native-url: undefined () neo-async: undefined () next: ^12.1.0 => 12.1.6 next-pwa: ^5.3.1 => 5.5.4 nextjs-progressbar: ^0.0.11 => 0.0.11 node-fetch: undefined () node-html-parser: undefined () nprogress: ^0.2.0 => 0.2.0 ora: undefined () os-browserify: undefined () p-limit: undefined () papaparse: ^5.3.1 => 5.3.2 path: ^0.12.7 => 0.12.7 path-browserify: undefined () postcss: ^8.3.6 => 8.4.14 (8.4.5, 7.0.39) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () prettier: 2.3.2 => 2.3.2 process: undefined () punycode: undefined () qrcode.react: ^3.0.1 => 3.0.2 (0.8.0) querystring-es3: undefined () raw-body: undefined () react: ^17.0.2 => 17.0.2 react-3d-viewer: ^1.0.12 => 1.0.12 react-beautiful-dnd: ^13.1.0 => 13.1.0 react-calendar: ^3.7.0 => 3.7.0 react-color: ^2.19.3 => 2.19.3 react-copy-to-clipboard: ^5.0.4 => 5.1.0 react-dom: 17.0.2 => 17.0.2 react-file-viewer-plus: ^0.1.2 => 0.1.2 react-flickity-component: ^3.6.2 => 3.6.2 react-icons: ^4.2.0 => 4.4.0 react-is: 17.0.2 react-refresh: 0.12.0 react-server-dom-webpack: undefined () react-trip-date: ^1.9.1 => 1.10.0 react-verification-code-input: ^1.2.9 => 1.2.9 react-window: ^1.8.7 => 1.8.7 react-zendesk: ^0.1.13 => 0.1.13 regenerator-runtime: 0.13.4 sass: ^1.38.2 => 1.52.2 sass-loader: undefined () save: ^2.4.0 => 2.5.0 schema-utils: undefined () semver: undefined () send: undefined () setimmediate: undefined () source-map: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () terser: undefined () text-table: undefined () three: ^0.139.2 => 0.139.2 (0.95.0, 0.85.2) throttle-debounce: ^5.0.0 => 5.0.0 timers-browserify: undefined () tty-browserify: undefined () type-fest: ^2.12.2 => 2.13.0 (0.21.3, 0.20.2, 0.16.0) typescript: ^4.4.2 => 4.7.3 ua-parser-js: undefined () unistore: undefined () use-async-queue: 2.1.5 => 2.1.5 use-subscription: undefined () util: undefined () uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2, ) vm-browserify: undefined () watchpack: undefined () web-streams-polyfill: undefined () web-vitals: undefined () webpack: ^5.51.1 => 5.73.0 () webpack-sources: undefined () ws: undefined () npmGlobalPackages: @aws-amplify/cli: 8.1.0 cognito-backup-restore: 1.3.2 npm-check-updates: 12.5.4 npm: 8.12.1 ts-node: 10.7.0 typescript: 4.6.2 ```

Describe the bug

I have the message type, shown below.

    @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.

Log output

``` // Put your logs below this line ```

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

LeoReubelt commented 2 years ago

I needed to remove @key(name: "byHasBeenRead", fields: ["hasBeenReadByIds"]).