You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our goal is to have a custom query returning complex typings, and to have it generated client side.
From what we understood, we have no choice but to declare the return type in the data/resources/schema.ts.
We tried creating our custom type, see steps to reproduce 1.
We tried using a .ref solution as mentioned in another thread, see steps to reproduce 2.
How could we declare our custom return type so that the client response is typed ? We don't need to create a model that will be stored, just a custom schema for the client to have the typings.
listCommits: a.query().returns(a.customType({commits: a.customType({author: a.string(),message: a.string()}).array(),// <--- here .array() does not exists}),).handler(a.handler.function(listCommits))
And we get
Property 'array' does not exist on type 'CustomType<{ fields: { author: ModelField<Nullable<string>, never, undefined>; message: ModelField<Nullable<string>, never, undefined>; }; }>'.ts(2339)
Thank you for the detailed issue description. I have been able reproduced the error you described in section 1.
For the schema you described in section 2 using a reference to a custom type, I was able to get a backend function working. Can you take a look at my example repo and help me identify what is different between our applications?
Marking this a feature request, as the example in section 1 is currently expected behavior and we were unable to reproduce the issue described in section 2. Please see Aaron's comment above.
stocaaro
transferred this issue from aws-amplify/amplify-category-api
Jan 8, 2025
Environment information
Describe the bug
Our goal is to have a custom query returning complex typings, and to have it generated client side.
From what we understood, we have no choice but to declare the return type in the
data/resources/schema.ts
.How could we declare our custom return type so that the client response is typed ? We don't need to create a model that will be stored, just a custom schema for the client to have the typings.
For now we are using
But this leads to the response being a string, and no types, which looses the benefits of using amplify on this query.
In an ideal world we could something like
Reproduction steps
1. Non working array version
And we get
2. Non working .ref version
But now, in our handler we get another typescript error telling us that we can not return what we return, missing properties:
It seems that our handler is now expecting some complex type from aws-amplify
The text was updated successfully, but these errors were encountered: