Skip to content

Commit d77899a

Browse files
jsw800zachdaniel
andauthored
add :none option to paginate_relationship_with (#336)
--------- Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
1 parent 23f0975 commit d77899a

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

documentation/dsls/DSL-AshGraphql.Resource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858
| [`derive_sort?`](#graphql-derive_sort?){: #graphql-derive_sort? } | `boolean` | `true` | Set to false to disable the automatic generation of a sort input for read actions. |
5959
| [`encode_primary_key?`](#graphql-encode_primary_key?){: #graphql-encode_primary_key? } | `boolean` | `true` | For resources with composite primary keys, or primary keys not called `:id`, this will cause the id to be encoded as a single `id` attribute, both in the representation of the resource and in get requests |
6060
| [`relationships`](#graphql-relationships){: #graphql-relationships } | `list(atom)` | | A list of relationships to include on the created type. Defaults to all public relationships where the destination defines a graphql type. |
61-
| [`paginate_relationship_with`](#graphql-paginate_relationship_with){: #graphql-paginate_relationship_with } | `keyword` | `[]` | A keyword list indicating which kind of pagination should be used for each `has_many` and `many_to_many` relationships, e.g. `related_things: :keyset, other_related_things: :offset`. Valid pagination values are `nil`, `:offset`, `:keyset` and `:relay`. |
61+
| [`paginate_relationship_with`](#graphql-paginate_relationship_with){: #graphql-paginate_relationship_with } | `keyword` | `[]` | A keyword list indicating which kind of pagination should be used for each `has_many` and `many_to_many` relationships, e.g. `related_things: :keyset, other_related_things: :offset`. Valid pagination values are `nil`, `:none`, `:offset`, `:keyset` and `:relay`. |
6262
| [`field_names`](#graphql-field_names){: #graphql-field_names } | `keyword` | | A keyword list of name overrides for attributes. |
6363
| [`hide_fields`](#graphql-hide_fields){: #graphql-hide_fields } | `list(atom)` | | A list of attributes to hide from the domain |
6464
| [`show_fields`](#graphql-show_fields){: #graphql-show_fields } | `list(atom)` | | A list of attributes to show in the domain. If not specified includes all (excluding `hide_fiels`). |

lib/resource/resource.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ defmodule AshGraphql.Resource do
392392
type: :keyword_list,
393393
default: [],
394394
doc:
395-
"A keyword list indicating which kind of pagination should be used for each `has_many` and `many_to_many` relationships, e.g. `related_things: :keyset, other_related_things: :offset`. Valid pagination values are `nil`, `:offset`, `:keyset` and `:relay`."
395+
"A keyword list indicating which kind of pagination should be used for each `has_many` and `many_to_many` relationships, e.g. `related_things: :keyset, other_related_things: :offset`. Valid pagination values are `nil`, `:none`, `:offset`, `:keyset` and `:relay`."
396396
],
397397
field_names: [
398398
type: :keyword_list,
@@ -1874,6 +1874,9 @@ defmodule AshGraphql.Resource do
18741874
nil ->
18751875
default_relationship_pagination_args()
18761876

1877+
:none ->
1878+
[]
1879+
18771880
:keyset ->
18781881
keyset_pagination_args(action)
18791882

lib/resource/verifiers/verify_paginate_relationship_with.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule AshGraphql.Resource.Verifiers.VerifyPaginateRelationshipWith do
88

99
@valid_strategies [
1010
nil,
11+
:none,
1112
:keyset,
1213
:offset,
1314
:relay

test/relationship_pagination_test.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,36 @@ defmodule AshGraphql.RelationshipPaginationTest do
223223
assert [%{"name" => "Award 2"} | _] = results
224224
end
225225

226+
test "works with :none strategy" do
227+
%{id: post_id} =
228+
AshGraphql.Test.Post
229+
|> Ash.Changeset.for_create(:create, text: "Post", published: true, score: 9.8)
230+
|> Ash.create!()
231+
232+
document =
233+
"""
234+
query GetPost($id: ID!) {
235+
getPostWithNoCommentPagination(id: $id) {
236+
id
237+
comments {
238+
id
239+
}
240+
}
241+
}
242+
"""
243+
244+
assert {:ok,
245+
%{
246+
data: %{
247+
"getPostWithNoCommentPagination" => %{
248+
"comments" => [],
249+
"id" => ^post_id
250+
}
251+
}
252+
}} =
253+
Absinthe.run(document, AshGraphql.Test.Schema, variables: %{"id" => post_id})
254+
end
255+
226256
describe "works when nested" do
227257
test "on return values for queries" do
228258
movie =

test/support/resources/post.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ defmodule AshGraphql.Test.Post do
195195

196196
queries do
197197
get :get_post, :read
198+
199+
get :get_post_with_no_comment_pagination, :read do
200+
paginate_relationship_with(comments: :none)
201+
end
202+
198203
get :get_post_with_custom_description, :read, description: "A custom description"
199204
list :post_library, :library
200205
list :paginated_posts, :paginated

0 commit comments

Comments
 (0)