Open TazChoudhury opened 2 weeks ago
Hi @TazChoudhury thank you for raising this issue and providing a detailed description and reproduction steps.
We will attempt to reproduce the issue and report back soon
Hi @TazChoudhury 👋 apologies for the delay. I was not able to able to reproduce this issue on the latest versions of @aws-amplify/backend
and @aws-amplify/backend-cli
packages, with the following schema.sql.ts
:
.schema({
"locations": a.model({
id: a.string().required(),
name: a.string().required(),
geom: a.string().required(),
address: a.string()
}).identifier([
"id"
]),
"posts": a.model({
id: a.string().required(),
title: a.string().required(),
published: a.boolean(),
owner: a.string()
}).identifier([
"id"
]),
graphql query:
query ($filter: ModelPostsFilterInput, $limit: Int, $nextToken: String) {
listPosts(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
title
published
owner
}
nextToken
__typename
}
client request:
const { data } = await client.models.posts.list();
console.log(data);
Data manager:
Client response:
@TazChoudhury I would recommend upgrading your backend and backend-cli packages to the latest version and see if that helps resolve the issue.
npm i @aws-amplify/backend @aws-amplify/backend-cli
Afterwards, run this to update the @aws-amplify/data-schema
package as well
npm update @aws-amplify/data-schema
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Storage
Amplify Version
v6
Amplify Categories
storage
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
Having run the command
npx ampx generate schema-from-database --connection-uri-secret SQL_CONNECTION_STRING --out amplify/data/schema.sql.ts
, I have theschema.sql.ts
file generated.The backend deploys successfully, and the
create
,update
, anddelete
commands work as expected. However thelist
command always returns an empty array for models where theidentifier
is a type that isa.string().required()
.Below model from
schema.sql.ts
doesn't work for list command:"auth": a.model({ user_id: a.string().required(), username: a.string().required(), password: a.string().required(), access: a.boolean(), created: a.datetime(), updated: a.datetime() }).identifier([ "user_id" ]),
It works when the model has an
identifier
of typea.integer().required()
. This model works for the list command:"one_off": a.model({ id: a.integer().required(), token: a.string(), amount: a.integer(), used: a.integer(), expiry_date: a.datetime(), created: a.datetime(), updated: a.datetime() }).identifier([ "id" ]),
This is potentially because the graphql request for listAuth from the
client.models.auth.list()
function call is:"query ($user_id: String, $sortDirection: ModelSortDirection, $filter: ModelAuthFilterInput, $limit: Int, $nextToken: String) {\n listAuths(\n user_id: $user_id\n sortDirection: $sortDirection\n filter: $filter\n limit: $limit\n nextToken: $nextToken\n ) {\n items {\n user_id\n username\n password\n access\n created\n updated\n }\n nextToken\n __typename\n }\n}\n"
This adds the identifier into the query as
$user_id: String
but this is empty and then won't return any data that matches.The graphql for the listOne_offs is:
query ($filter: ModelOne_offFilterInput, $limit: Int, $nextToken: String) { listOne_offs(filter: $filter, limit: $limit, nextToken: $nextToken) { items { id token amount used expiry_date created updated } nextToken __typename } }
Id isn't included and so all the data is returned from the list command.
I know the connection has been made to the database due to the other commands working and I can also see the data in the
Data Manager
view.Expected behavior
The expected behaviour is that the list command works with generated models with string types as their id.
Reproduction steps
const result = await client.models.[type].list();
in the app.