-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow refering models from custom types in Gen 2 to allow for basic usable argument/return types in custom queries/mutations #2950
Comments
This is a blocker for me since my custom list & search queries need to return my model's items but without being able to return a nextToken they're kind of useless atm. |
Hey @thomasoehri, Thanks for requesting this. We are marking this as a feature request for the team to evaluate further. |
Hi @AnilMaktala, I also encountered this problem. Looking forward to your solutions |
@AnilMaktala - This is a big blocker for custom queries. There should be a type in the generated schema for the referenced model looks like this:
How do we get a hold of this object for reference on the TS side of things? Is it nested in the Schema type somewhere? |
Work around I just implemented for anyone whose blocked by this. The trick is to duplicate the model, and make the dupe a customType. Its annoying but works. // The model I'm working with and trying to integrate search with:
Feedback: a.model({
title: a.string().required(),
...
}),
// Duplicate that allows referencing:
Feedback2: a.customType({
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("Feedback2").array(),
nextToken: a.string(),
scannedCount: a.integer(),
startedAt: a.timestamp()
}),
searchFeedback: a.query()
.arguments({
...
})
// Referencing the custom return type from above:
.returns(a.ref("SearchableFeedbackConnection"))
.handler(a.handler.custom({
dataSource: a.ref('MasterTenantTable'),
entry: './MyResolverId.js',
})), Appsync will often be none the wiser because the schemas match. However you still won't be able to get |
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:
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: #2560
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:
Additional context
No response
Is this something that you'd be interested in working on?
Would this feature include a breaking change?
The text was updated successfully, but these errors were encountered: