Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path override for page limit breaks paging links #527

Closed
ryguyk opened this issue Sep 20, 2023 · 1 comment
Closed

path override for page limit breaks paging links #527

ryguyk opened this issue Sep 20, 2023 · 1 comment

Comments

@ryguyk
Copy link

ryguyk commented Sep 20, 2023

Problem

When using the path override for increasing the JSON:API page limit, the next paging link is not correct.

Examples

/* services.yml */
next_jsonapi.size_max: 100

Let's say we have more than 100 resources that need to be fetched. The goal is to be able to grab them all by fetching the first page and then recursively looking at the next link on the result and gluing all the pages together until no next link is found. This process might seem to negate the need for the path/page-limit override in the first place, but, in the case where there are thousands of resources, it would be nice to be able to fetch pages of larger size to limit the number of requests.

  1. Without path override (works as expected)

    • Request:
      /jsonapi/node/news_story?page[offset]=50&page[limit]=50
    • Response (links only):
      {
        first: {
          href: "[DOMAIN]/jsonapi/node/news_story?page[offset]=0&page[limit]=50",
        },
        last: {
          href: "[DOMAIN]/jsonapi/node/news_story?page[offset]=3000&page[limit]=50",
        },
        next: {
          href: "[DOMAIN]/jsonapi/node/news_story?page[offset]=100&page[limit]=50",
        },
        prev: {
          href: "[DOMAIN]/jsonapi/node/news_story?page[offset]=0&page[limit]=50",
        },
        self: {
          href: "[DOMAIN]/jsonapi/node/news_story?page[offset]=50&page[limit]=50",
        },
      }
      
      Note: All links are present and include correct paging parameters
  2. With path override but no paging parameters (fetch first page - kind of works as expected)

    • Request
      /jsonapi/node/news_story?fields[node--news_story]=path
    • Response (links only)
      {
        last: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=3000&page[limit]=100",
        },
        next: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=100&page[limit]=100",
        },
        self: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path",
        },
      }
      
      Note: first and prev links are missing but next link is populated and looks correct. However, see below for what happens when you follow that next link.
  3. With path override and paging variables (fetch subsequent page - BROKEN)

    • Request
      /jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=100&page[limit]=100
    • Response (links only)
      {
        last: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=3000&page[limit]=100",
        },
        next: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=100&page[limit]=100",
        },
        self: {
          href: "[DOMAIN]/jsonapi/node/news_story?fields[node--news_story]=path&page[offset]=100&page[limit]=100",
        },
      }
      
      Note: Again, first and prev links are missing. More importantly, the next link is the same as the self link. This will create infinite recursion when trying to glue the pages together. Also, when looking at the actual data (omitted), it appears to be the same as the original page (i.e. the page[offset] does not seem to have any effect).
@fiasco
Copy link
Contributor

fiasco commented Feb 23, 2024

I had a type which I've corrected in #702

JohnAlbin pushed a commit that referenced this issue Feb 23, 2024
marcorcau pushed a commit to marcorcau/next-drupal that referenced this issue Mar 26, 2024
marcorcau pushed a commit to marcorcau/next-drupal that referenced this issue Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants