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