diff --git a/backend/lib/edgehog/base_images/base_image_collection.ex b/backend/lib/edgehog/base_images/base_image_collection.ex index 841b9c05d..8148ce7cb 100644 --- a/backend/lib/edgehog/base_images/base_image_collection.ex +++ b/backend/lib/edgehog/base_images/base_image_collection.ex @@ -39,6 +39,8 @@ defmodule Edgehog.BaseImages.BaseImageCollection do graphql do type :base_image_collection + + paginate_relationship_with base_images: :relay end actions do diff --git a/backend/lib/edgehog/base_images/base_images.ex b/backend/lib/edgehog/base_images/base_images.ex index 3e07d0ba9..151f472b4 100644 --- a/backend/lib/edgehog/base_images/base_images.ex +++ b/backend/lib/edgehog/base_images/base_images.ex @@ -45,7 +45,7 @@ defmodule Edgehog.BaseImages do list BaseImageCollection, :base_image_collections, :read do description "Returns a list of base image collections." - paginate_with nil + relay? true end end diff --git a/backend/test/edgehog_web/schema/mutation/create_base_image_collection_test.exs b/backend/test/edgehog_web/schema/mutation/create_base_image_collection_test.exs index 80aecaeda..9f17d10ae 100644 --- a/backend/test/edgehog_web/schema/mutation/create_base_image_collection_test.exs +++ b/backend/test/edgehog_web/schema/mutation/create_base_image_collection_test.exs @@ -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 @@ -159,6 +162,15 @@ defmodule EdgehogWeb.Schema.Mutation.CreateBaseImageCollectionTest do name handle } + baseImages { + count + edges { + node { + id + version + } + } + } } } } diff --git a/backend/test/edgehog_web/schema/query/base_image_collection_test.exs b/backend/test/edgehog_web/schema/query/base_image_collection_test.exs index e816cf302..a35b06c11 100644 --- a/backend/test/edgehog_web/schema/query/base_image_collection_test.exs +++ b/backend/test/edgehog_web/schema/query/base_image_collection_test.exs @@ -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 @@ -94,8 +99,13 @@ defmodule EdgehogWeb.Schema.Query.BaseImageCollectionTest do name handle baseImages { - id - version + count + edges { + node { + id + version + } + } } systemModel { id diff --git a/backend/test/edgehog_web/schema/query/base_image_collections_test.exs b/backend/test/edgehog_web/schema/query/base_image_collections_test.exs index 081edebf8..008f15d7d 100644 --- a/backend/test/edgehog_web/schema/query/base_image_collections_test.exs +++ b/backend/test/edgehog_web/schema/query/base_image_collections_test.exs @@ -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 @@ -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 @@ -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 + } + } } } } @@ -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