1 個回答
- 最新
- 最多得票
- 最多評論
0
It turns out I was neglecting to use the nextToken in the payload. the query will only look at 10 elements at a time by default so it's the dev's responsiblity to continue querying until they have enough matching results
Example of method to use nextToken:
/**
- @desc Recursively fetch all items in a list query using nextToken
- @param {Object} query The query object from cda-graphql in use.
- @param {Object} variables The variables to pass to query.
- @returns {Array} Array of all items received from queries.
*/
import { API, graphqlOperation } from 'aws-amplify';
async function fetchItemsNextToken({ query, variables, limit}) {
const results = [];
while (results.length < limit) {
const { data } = await API.graphql(graphqlOperation(query, variables));
const key = Object.keys(data).find(k => k.includes('list'));
const res = data[key]; // res = { items: [], nextToken: '' }
results.push(...res.items);
if (!res.nextToken) break;
// eslint-disable-next-line no-param-reassign
variables.nextToken = res.nextToken;
}
return new Promise((resolve, reject) => {
resolve(results);
});
}
export default fetchItemsNextToken;
已回答 4 年前
相關內容
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前