diff --git a/addons/api/addon/adapters/application.js b/addons/api/addon/adapters/application.js index 763cb6d98..18e1c3c67 100644 --- a/addons/api/addon/adapters/application.js +++ b/addons/api/addon/adapters/application.js @@ -118,12 +118,34 @@ export default class ApplicationAdapter extends RESTAdapter.extend( /** * Intercepts "empty" responses and adds an empty `items` array. + * This query method now supports pagination by checking the responseType and + * passing in the refresh token if the responseType indicates more data * @override * @method query * @return {Promise} promise */ - query() { - return super.query(...arguments).then(prenormalizeArrayResponse); + async query(store, schema, query) { + let result; + let data = []; + + // Run this loop as long as the response_type is delta, + // which indicates that there are more items in the list + do { + result = await super.query(store, schema, query); + //add the result items to a data array + if (result && result.items) { + data.push(...result.items); + //pass in the refresh token for subsequent calls to fetch the remaining list items + query.refresh_token = result.refresh_token; + //break the loop as soon the response_type becomes complete + if (result.response_type === 'complete') { + break; + } + } + } while (result && result.response_type === 'delta'); + + result.items = data; + return prenormalizeArrayResponse(result); } /** diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index 52f9c813d..3e631334f 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -149,7 +149,7 @@ export default class ApplicationSerializer extends RESTSerializer { ); // Copy the data rooted under `items` in the existing payload into the new // payload under the expected root key name. - transformedPayload[payloadKey] = structuredClone(payload.items); + transformedPayload[payloadKey] = structuredClone(payload?.items); // Return the result of normalizing the transformed payload. return super.normalizeArrayResponse( store,