Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3233,16 +3233,16 @@ defmodule AshGraphql.Graphql.Resolver do

defp apply_load_arguments(arguments, query, will_paginate?) do
Enum.reduce(arguments, query, fn
{:limit, limit}, query when not will_paginate? ->
{:limit, limit}, query when is_integer(limit) and not will_paginate? ->
Ash.Query.limit(query, limit)

{:offset, offset}, query when not will_paginate? ->
{:offset, offset}, query when is_integer(offset) and not will_paginate? ->
Ash.Query.offset(query, offset)

{:filter, value}, query ->
{:filter, value}, query when is_map(value) ->
Ash.Query.filter_input(query, massage_filter(query.resource, value))

{:sort, value}, query ->
{:sort, value}, query when is_list(value) ->
keyword_sort =
Enum.map(value, fn %{order: order, field: field} = input ->
case Ash.Resource.Info.calculation(query.resource, field) do
Expand Down
34 changes: 34 additions & 0 deletions test/paginate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,40 @@ defmodule AshGraphql.PaginateTest do
}
}} = Absinthe.run(doc, AshGraphql.Test.Schema)
end

test "does not raise when limit, offset, filter, or sort are nil in nested query" do
doc = """
query PaginatedPosts($commentsLimit: Int, $commentsOffset: Int, $commentsSort: [CommentSortInput], $commentsFilter: CommentFilterInput) {
paginatedPosts(limit: 2, offset: 2) {
count
results{
comments(limit: $commentsLimit, offset: $commentsOffset, sort: $commentsSort, filter: $commentsFilter){
text
}
}
}
}
"""

variables = %{}

assert {:ok,
%{
data: %{
"paginatedPosts" => %{
"count" => 5,
"results" => [
%{
"comments" => _
},
%{
"comments" => _
}
]
}
}
}} = Absinthe.run(doc, AshGraphql.Test.Schema, variables: variables)
end
end

describe "pagination errors" do
Expand Down
Loading