limit 参数,例如:query listPosts {
listPosts(limit: 10) {
items {
id
title
content
}
}
}
nextToken 来限制数量,例如:query listPosts {
listPosts(limit: 10, nextToken: $nextToken) {
items {
id
title
content
}
nextToken
}
}
其中 $nextToken 是一个变量,你可以从上一页的查询结果中获取它。
query 方法并传递 ScanIndexForward 和 Limit 参数,例如:import { DataStore } from 'aws-amplify';
import { Post } from './models';
const posts = await DataStore.query(Post, c => c
.where('category', 'eq', 'news')
.sort(SortDirection.DESCENDING, 'createdAt')
.limit(10)
);
其中的 limit 参数可以限制查询结果的数量,这个方法支持更复杂的查询操作。