I am using AWS Amplify (with Cli and Angular 7 for front end) for Graphql/AppSync and wondering how to get all connected items when it exceeds 10 items?
Let's say I have created a schema.graphql like this:
type User @model {
id: ID!
firstname: String
lastname: String
project: Project @connection(name: "ProjectUsers")
}
type Project @model {
id: ID!
title: String
task: String
members: [User] @connection(name: "ProjectUsers")
}
When running amplify push it generates queries and mutations. When running the GetProject query with the id of a project (from the generated API.service.ts file) it returns the Project item with the connected Users. But if the project have more than 10 Users, it only gives me the 10 first users and a next token:
{
id: "67b1fc0a-fd1f-4e8b-9bd7-b82b2aea5d3b",
title: "Test",
task: "test",
members: {
items: {
0: {__typename: "User", id: "f245809a...}
1: ...
(2-8: ...)
9: ...
nextToken: "qwerj23r2kj....3223oop32kjo",
__typename: "ModelUserConnection";
}
}
__typename: "Project"
}
I can see multiple solutions for this, but not how to do them:
Is it possible to change schema.grapql to change the codegen so that it can generate the ability to change the limit, ex. 100 instead of the standard 10?
Use the nextToken to paginate the results, from the generated API.service.ts file?
Change the schema.graphql file so that the generated ModelUserFilterInput has the userProjectId field (to use in the generated ListUsers query)?
Or are there any other solutions to get all the Users of a Project with the queries in the automatically generated file (API.service.ts)?
As of now the only solution I can see is to first run the ListUsers query (without any filters), and then loop through all of them to check if it has the correct project id. But if the users database is large this can grow to be a lot of data and be really slow, and the benefits to use @connection isn't really there.
Sorry for long post and I hope I have explained the problem enough.