Option to Get All Resources

Created on 1 November 2023, about 1 year ago
Updated 2 February 2024, 10 months ago

Problem/Motivation

Provide an option to get all results for a collection rather than being limited to paged results.

Proposed resolution

The getCollection method will accept a boolean 'all' option. If this is provided, we'll iterate through all pages of JSON:API results to return all data rather than returning only one page of results.

getResource and getCollection currently share the GetOptions interface. We might need to extend this in a new GetCollectionOptions interface - I don't think an all option makes sense for getting a single resource.

Remaining tasks

* Implement 'all' option for getResource.
* Add test coverage.
* Add inline documentation.

API changes

Options for getCollection will now accept a boolean 'all' option.

Feature request
Status

Postponed

Component

Code

Created by

🇺🇸United States brianperry

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @brianperry
  • 🇮🇳India pratik_kamble Pune, India

    @brianperry I did not fully understand what is expected output here? Do we want to disable pagination? Because as far as I know we can't get disable pagination for JSONAPI client.

  • 🇺🇸United States brianperry

    @pratik_kamble - you are correct that there is no way to disable paging of the JSON:API endpoint. This would essentially be providing a helper on our end to automatically get all paged results.

    In DrupalState we had an 'all' option

    // If there is a collection with more than 50 entries, Drupal will automatically
    // paginate results and return the first 50 items.
    // To fetch all items in a collection, use the `all` option
    const allArticlesFromApi = await store.getObject({
      objectName: 'node--ds_example',
      all: true,
    });

    This passage of code is how we approached it in that library: https://git.drupalcode.org/project/drupal_state/-/blob/1.0.x/src/DrupalS...

  • 🇺🇸United States brianperry

    Added a little more detail to the issue description.

  • Assigned to pratik_kamble
  • 🇮🇳India pratik_kamble Pune, India

    @brianperry What should be response if the both `rawreponse` and `all` flag is true.

  • Status changed to Postponed 10 months ago
  • 🇺🇸United States brianperry

    @pratik_kamble that's a good question. If forced to choose with both flags I think 'all' would have to override 'rawResponse' - either just ignoring it, or throwing an error when both exist.

    But as you seem to imply, that feels like it is in conflict with our interface. And the JSON:API spec for that matter.

    I'm inclined to say that we postpone this for now in favor of leading people to use JSON:API as intended by the spec. If we hear demand for this feature we can reconsider.

  • Issue was unassigned.
Production build 0.71.5 2024