Invalid nextToken type in generated schema with @searchable
See original GitHub issueDescribe the bug In generated schema for models that has @searchable attribute there are generated search* methods with invalid nextToken type - Int. These methods returns nextToken as Long (encoded as String) so one cannot continue searching with this token because of following error returned from GraphQL API endpoint:
{
"message": "Variable 'nextToken' has an invalid value. Expected type 'Int' but was 'Long'."
}
To Reproduce Steps to reproduce the behavior:
- Generate schema using amplify push for model:
type Customer
@model(mutations: { create: "createCustomer", update: "updateCustomer" })
@searchable
@auth(rules: [
{ allow: groups, groups: ["Administrators"] },
]) {
data: AWSJSON
isArchived: Boolean!
createdAt: AWSDateTime
id: ID!
name: String!
address: String
description: String
phone: String
email: String
}
- In generated schema we have:
searchCustomers(
filter: SearchableCustomerFilterInput,
sort: SearchableCustomerSortInput,
limit: Int,
nextToken: Int
): SearchableCustomerConnection
- Try to search using this method with some low limit to get results & nextToken:
{
"searchCustomers": {
"__typename": "SearchableCustomerConnection",
"items": [ ... ],
"nextToken": "1547964054859"
}
}
- Try use generated value (ex. 1547964054859) in next search as nextToken:
{
"message": "Variable 'nextToken' has an invalid value. Expected type 'Int' but was 'Long'."
}
Expected behavior Something is wrong with generated schema AND typescript (I’m using Angular) code. Search* method returns very long number in response as a string but expects Int in next call.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:11 (1 by maintainers)
Top Results From Across the Web
AppSync GraphQL query with nextToken - Stack Overflow
Here is the schema file that generates query automatically. schema.graphql type User @model { id: String! uuid: String! following: [String] ...
Read more >Search Schemas - AWS Documentation
v1/registries/name/ registryName /schemas/search Operation ID: ... nextToken, String, False ... Valid types include OpenApi3 and JSONSchemaDraft4 .
Read more >API (GraphQL) - GraphQL pagination - JavaScript - Amplify Docs
The nextToken is what is used to handle pagination. If the nextToken is null , that means that there is no more data...
Read more >A problem with pagination AWS Amplify API
I don't know what to do next with nextToken. This GraphQL schema: type Note @model @auth(rules: [{allow: owner, ownerField: "user"}]) { id: ID!...
Read more >RedshiftDataAPIService — Boto3 Docs 1.26.34 documentation
This value is a universally unique identifier (UUID) generated by Amazon Redshift ... For more information, see Data types in the Amazon Redshift...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I did hours of research on this today. I think the implementation is incorrect. The code is assuming that search works the same way as list and that the entry in sort can be used as a nextToken.
That is how DynamoDB backend works, but not how the ElasticSearch backend works. ElasticSearch implements from and it should be an offset. i.e. if you want the 11-20th records you would set from to 11. Similar to SQL
OFFSET
I think nextToken should be renamed to offset or from for a search and the code trying to add nextToken to the response should be removed.
Could be wrong, but hust using ```{ limit: pageSize, nextToken: page*pageSize } works for me, and also makes sense that it is an int.
The above isn’t a great description but I’m in a rush at the moment. If it’s not clear I can provide more detail later
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.