question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid nextToken type in generated schema with @searchable

See original GitHub issue

Describe 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:

  1. 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
}
  1. In generated schema we have:
	searchCustomers(
		filter: SearchableCustomerFilterInput,
		sort: SearchableCustomerSortInput,
		limit: Int,
		nextToken: Int
	): SearchableCustomerConnection
  1. Try to search using this method with some low limit to get results & nextToken:
{
  "searchCustomers": {
    "__typename": "SearchableCustomerConnection",
    "items": [ ... ],
    "nextToken": "1547964054859"
  }
}
  1. 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
johnfcommented, Feb 17, 2019

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

0reactions
github-actions[bot]commented, Jun 9, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found