Description
Describe the feature you'd like to request
I'm integrating OpenSearch in my Gen 2 backend using custom queries where i need to return the items, nextToken as well as the total. The only way of doing this is using a custom type as the return type of the custom query:
// The model i'm working with and trying to integrate search with:
Feedback: a
.model({
title: a.string().required(),
...
}),
// The custom type that defines the structure of the return type of the custom search query:
SearchableFeedbackConnection: a.customType({
items: a.ref("Feedback").array().required(),
nextToken: a.string(),
total: a.integer(),
}),
searchFeedback: a
.query()
.arguments({
...
})
// Referencing the custom return type from above:
.returns(
a.ref("SearchableFeedbackConnection")
)
This results in the following error:
Cannot use ".ref()" to refer a model from a "custom type". Field "items" of "SearchableFeedbackConnection" refers to model "Feedback"
The problem is that i NEED to return the nextToken alongside all Feedback items. So i can't just return .returns(a.ref("Feedback").array())
, which wouldn't result in the error.
The problem isn't isolated to the opensearch example above, i have this issue using custom queries/mutations in general, for example in all my custom list queries where i also need to return the nextToken to be able to query for the next batch of items.
And the same goes for arguments: aws-amplify/amplify-data#451
Describe the solution you'd like
I want to be able to refer to models from custom types so that custom queries work.
Describe alternatives you've considered
Creating another custom type that represents a Feedback instead of using the "Feedback" model obviously doesn't result in the above error but also doesn't have all the field-level authorization rules and relationships that allow for nested queries the model has:
// This does not work since i need all the field-level authorization rules and the ability to perform nested queries using the
// relationships on the "Feedback" model
FeedbackResponse: a.customType({
...
}),
SearchableFeedbackConnection: a.customType({
items: a.ref("FeedbackResponse").array().required(),
nextToken: a.string(),
total: a.integer(),
}),
Additional context
No response
Is this something that you'd be interested in working on?
- 👋 I may be able to implement this feature request
Would this feature include a breaking change?
-
⚠️ This feature might incur a breaking change