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

feat!(pagination): paginate base_image_collection #784

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
2 changes: 2 additions & 0 deletions backend/lib/edgehog/base_images/base_image_collection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ defmodule Edgehog.BaseImages.BaseImageCollection do

graphql do
type :base_image_collection

paginate_relationship_with base_images: :relay
end

actions do
Expand Down
3 changes: 2 additions & 1 deletion backend/lib/edgehog/base_images/base_images.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ defmodule Edgehog.BaseImages do

list BaseImageCollection, :base_image_collections, :read do
description "Returns a list of base image collections."
paginate_with nil
relay? true
paginate_with :keyset
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ defmodule EdgehogWeb.Schema.Mutation.CreateBaseImageCollectionTest do
"id" => ^system_model_id,
"name" => ^system_model_name,
"handle" => ^system_model_handle
},
"baseImages" => %{
"edges" => []
}
} = base_image_collection
end
Expand Down Expand Up @@ -159,6 +162,15 @@ defmodule EdgehogWeb.Schema.Mutation.CreateBaseImageCollectionTest do
name
handle
}
baseImages {
count
edges {
node {
id
version
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionTest do
result = base_image_collection_query(tenant: tenant, id: base_image_collection_id)

assert %{
"baseImages" => [
%{
"id" => ^base_image_id,
"version" => "2.0.0"
}
]
"baseImages" => %{
"count" => 1,
"edges" => [
%{
"node" => %{
"id" => ^base_image_id,
"version" => "2.0.0"
}
}
]
}
} = extract_result!(result)
end
end
Expand All @@ -94,8 +99,13 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionTest do
name
handle
baseImages {
id
version
count
edges {
node {
id
version
}
}
}
systemModel {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionsTest do

describe "baseImageCollections field" do
test "returns empty base image collections", %{tenant: tenant} do
assert %{data: %{"baseImageCollections" => []}} ==
base_image_collections_query(tenant: tenant)
assert [] = [tenant: tenant] |> base_image_collections_query() |> extract_result!()
end

test "returns base image collections if they're present", %{tenant: tenant} do
Expand All @@ -39,8 +38,8 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionsTest do
system_model_id: system_model.id
)

assert %{data: %{"baseImageCollections" => [base_image_collection]}} =
base_image_collections_query(tenant: tenant)
assert [base_image_collection] =
[tenant: tenant] |> base_image_collections_query() |> extract_result!()

assert base_image_collection["name"] == fixture.name
assert base_image_collection["handle"] == fixture.handle
Expand All @@ -55,10 +54,15 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionsTest do
"""
query BaseImageCollections($filter: BaseImageCollectionFilterInput, $sort: [BaseImageCollectionSortInput]) {
baseImageCollections(filter: $filter, sort: $sort) {
name
handle
systemModel {
id
count
edges {
node {
name
handle
systemModel {
id
}
}
}
}
}
Expand All @@ -75,4 +79,15 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionsTest do

Absinthe.run!(document, EdgehogWeb.Schema, variables: variables, context: %{tenant: tenant})
end

defp extract_result!(result) do
assert %{data: %{"baseImageCollections" => %{"count" => count, "edges" => edges}}} = result
refute :errors in Map.keys(result)

base_image_collections = Enum.map(edges, & &1["node"])

assert length(base_image_collections) == count

base_image_collections
end
end
Loading