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
87 stars 73 forks source link

Argument Type Error in Array Field #2682

Closed jewells07 closed 1 month ago

jewells07 commented 1 month ago

Amplify CLI Version

12.12.2

Question

// Model

Todo: a.model({
  content: a.string(),
  tags: a.string().array(),
})

// Nuxt 3 code. I have created a plugin and can use $Amplify by following the steps in this document. Note: the link may redirect to Gen 1, but please check for Gen 2.

  const { data, errors } = await $Amplify.GraphQL.client.models.Todo.get(
    {
      id: '123456',
    },
    {
      selectionSet: ['tags'],
      authMode: 'userPool',
    },
  );

  const isTag = data.tags.includes('SPORTS');

The following code displays the type error: Argument of type 'string' is not assignable to parameter of type 'string[]'. When I hover over data, I see readonly tags: string[][];. Why does it show a 2D array when I have tags: ['SPORTS', 'TECH', 'MARKETING']?

chrisbonifacio commented 1 month ago

Hi @jewells07 I was not able to reproduce this issue with the given schema and code snippet.

Here's a screenshot of the type when I hover over data.tags

CleanShot 2024-07-11 at 00 22 22

And here's my reproduction app - the code is on the issue2682 branch

I did run into some errors around types, not the exact one you ran into. I had to uninstall the Vetur extension in VSCode, restarting VSCode (not just extensions), and making sure all my amplify packages were up to date by running the following commands:

npm i @aws-amplify/backend@latest @aws-amplify/backend-cli@latest 

and

npm update @aws-amplify/data-schema
chrisbonifacio commented 1 month ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

github-actions[bot] commented 1 month ago

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.