-
-
Notifications
You must be signed in to change notification settings - Fork 371
feat: add paginate_by_default? option to read actions #2648
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,12 @@ defmodule Ash.Resource.Actions.Read do | |
| doc: | ||
| "Whether or not pagination can be disabled (by passing `page: false` to `Ash.Api.read!/2`, or by having `required?: false, default_limit: nil` set). Only relevant if some pagination configuration is supplied.", | ||
| default: true | ||
| ], | ||
| paginate_by_default?: [ | ||
| type: :boolean, | ||
| doc: | ||
| "Whether or not to paginate by default when pagination is not required and no page parameters are provided.", | ||
| default: false | ||
| ] | ||
|
Comment on lines
+153
to
158
|
||
| ] | ||
|
|
||
|
|
@@ -160,6 +166,7 @@ defmodule Ash.Resource.Actions.Read do | |
| countable: false, | ||
| stable_sort: nil, | ||
| required?: false, | ||
| paginate_by_default?: false, | ||
| keyset?: false, | ||
| offset?: false, | ||
| __spark_metadata__: nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,14 @@ defmodule Ash.Actions.PaginationTest do | |||||||||||||||||||
| pagination offset?: true, countable: true, required?: false | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| read :paginate_by_default do | ||||||||||||||||||||
| pagination offset?: true, | ||||||||||||||||||||
| countable: true, | ||||||||||||||||||||
| required?: false, | ||||||||||||||||||||
| paginate_by_default?: true, | ||||||||||||||||||||
| default_limit: 3 | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| read :offset_countable_by_default do | ||||||||||||||||||||
| pagination offset?: true, countable: :by_default, required?: false | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
@@ -308,6 +316,14 @@ defmodule Ash.Actions.PaginationTest do | |||||||||||||||||||
|
|
||||||||||||||||||||
| assert %{results: [%{name: "3"}]} = Ash.page!(page, :self) | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| test "paginate_by_default? applies default limit when no page opts" do | ||||||||||||||||||||
| assert %Ash.Page.Offset{results: results} = | ||||||||||||||||||||
| User | ||||||||||||||||||||
| |> Ash.read!(action: :paginate_by_default) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| assert Enum.count(results) == 3 | ||||||||||||||||||||
|
||||||||||||||||||||
| assert Enum.count(results) == 3 | |
| assert Enum.count(results) == 3 | |
| results = | |
| User | |
| |> Ash.read!(action: :paginate_by_default, page: false) | |
| assert is_list(results) | |
| assert Enum.count(results) == 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This DSL reference entry for
paginate_by_default?should mention that clients can still disable pagination withpage: false, and that the option only has an effect when adefault_limitis configured.