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
90 stars 76 forks source link

client.model.[modeltype].list() returning empty array #2946

Open M-Mbrane opened 1 day ago

M-Mbrane commented 1 day ago

Environment information

System:
  OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
  CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
  Memory: 5.78 GB / 15.32 GB
  Shell: /bin/bash
Binaries:
  Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.1
  @aws-amplify/backend: 1.4.0
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.2.9
  @aws-amplify/backend-data: 1.1.4
  @aws-amplify/backend-deployer: 1.1.4
  @aws-amplify/backend-function: 1.6.0
  @aws-amplify/backend-output-schemas: 1.3.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.3
  @aws-amplify/backend-storage: 1.2.1
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.4.0
  @aws-amplify/deployed-backend-client: 1.4.1
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.3
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.6.4
  aws-cdk: 2.154.1
  aws-cdk-lib: 2.154.1
  typescript: 5.6.2
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

Wheh I run something like :

const { data: substrands } = await client.models.substrands.list()

an empty array is returned instead of the list of items. The connection to the DB seems to be fine, and when I run for example :

await client.models.substrands.get({substrand_id : 1})

which returns the following :

{
    "substrand_id": 1,
    "substrand_name": "Nature and development of science",
    "strand_id": 1
}

The expected data is returned. It seems to not matter if I pass a selectionSet, or filter or any other option to list(), it always returns an empty array (and no errors). It returns the below :

{
    "data": [],
    "nextToken": null
} 

This is happening for all models defined in the generated schema.sql.ts

Reproduction steps

excerpt from schema.sql.ts generated by runninng

npx ampx generate schema-from-database --connection-uri-secret SQL_CONNECTION_STRING --out amplify/data/schema.sql.ts

 "substrands": a.model({
        substrand_id: a.integer().required(),
        substrand_name: a.string().required(),
        strand_id: a.integer().required()
    }).identifier([
        "substrand_id"
    ])

running :

        const {data : single_substrand} = await client.models.substrands.get({substrand_id : 1})
        console.log(single_substrand); //prints single record
        const  { data: substrands } = await client.models.substrands.list()
        console.log(substrands) //empty array returned. 
ykethan commented 1 day ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂