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

Implement pagination feature for related routes #230

Open
sangeethailango opened this issue Sep 13, 2024 · 0 comments
Open

Implement pagination feature for related routes #230

sangeethailango opened this issue Sep 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sangeethailango
Copy link

sangeethailango commented Sep 13, 2024

Problem:

The pagination feature is currently not functioning as expected for related routes in the ash_json_api gem. Specifically, when fetching related records for a resource, the records are returned without pagination, even though pagination is correctly implemented for the primary resource.

Example setup:

  use Ash.Resource,
    domain: Account.Domain,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshJsonApi.Resource]

  ...
  
actions do
    read :read do  
      pagination countable: true, offset?: true, required?: true, default_limit: 10
    end
  end

  relationships do
    has_many :comments, Comment
  end
end

comment resource

  use Ash.Resource,
    domain: Account.Domain,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshJsonApi.Resource]

  ...
  
  actions do
   read :read do  
      pagination countable: true, offset?: true, required?: true, default_limit: 10
   end
  end

  relationships do
    belongs_to, :article, Article
  end
end

Domain

defmodule Account.Domain do
  use Ash.Domain, extensions: [AshJsonApi.Domain]

  alias Accounts.Blog.{Article, Comment}
  
  json_api do
    routes do
      base_route "/articles", Article do
        get :read
        related :comments, :read
      end
    end
  end

When making a GET request to articles/:article_id/comments, the related comments are not paginated. However, pagination works correctly when fetching the articles directly from /articles.

Expected Behavior:

The pagination functionality should be applied to related routes just as it is for the primary resource. For instance, when accessing related comments through the endpoint articles/:article_id/comments, the response should include pagination controls and adhere to the pagination settings defined for the :read action on the Comment resource.

Proposed Solution:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Someday
Development

No branches or pull requests

2 participants