diff --git a/backend/lib/edgehog/update_campaigns/update_campaigns.ex b/backend/lib/edgehog/update_campaigns/update_campaigns.ex index f08d189c6..6ea201f98 100644 --- a/backend/lib/edgehog/update_campaigns/update_campaigns.ex +++ b/backend/lib/edgehog/update_campaigns/update_campaigns.ex @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,7 +50,8 @@ defmodule Edgehog.UpdateCampaigns do list UpdateChannel, :update_channels, :read do description "Returns a list of update channels." - paginate_with nil + paginate_with :keyset + relay? true end end diff --git a/backend/lib/edgehog/update_campaigns/update_channel/update_channel.ex b/backend/lib/edgehog/update_campaigns/update_channel/update_channel.ex index f6e765eff..d524b8617 100644 --- a/backend/lib/edgehog/update_campaigns/update_channel/update_channel.ex +++ b/backend/lib/edgehog/update_campaigns/update_channel/update_channel.ex @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,8 @@ defmodule Edgehog.UpdateCampaigns.UpdateChannel do graphql do type :update_channel + + paginate_relationship_with target_groups: :relay, update_campaigns: :relay end actions do diff --git a/backend/test/edgehog_web/schema/mutation/create_update_channel_test.exs b/backend/test/edgehog_web/schema/mutation/create_update_channel_test.exs index 154d9e34c..f3116dd4d 100644 --- a/backend/test/edgehog_web/schema/mutation/create_update_channel_test.exs +++ b/backend/test/edgehog_web/schema/mutation/create_update_channel_test.exs @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -42,7 +42,10 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do assert update_channel_data["name"] == "My Update Channel" assert update_channel_data["handle"] == "my-update-channel" - assert [target_group_data] = update_channel_data["targetGroups"] + + assert [target_group_data] = + extract_nodes!(update_channel_data["targetGroups"]["edges"]) + assert target_group_data["id"] == target_group_id assert target_group_data["name"] == target_group.name assert target_group_data["handle"] == target_group.handle @@ -210,9 +213,13 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do name handle targetGroups { - id - name - handle + edges { + node { + id + name + handle + } + } } } } @@ -274,4 +281,8 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do id end + + defp extract_nodes!(data) do + Enum.map(data, &Map.fetch!(&1, "node")) + end end diff --git a/backend/test/edgehog_web/schema/mutation/update_update_channel_test.exs b/backend/test/edgehog_web/schema/mutation/update_update_channel_test.exs index b4b1e3a47..6e7971c06 100644 --- a/backend/test/edgehog_web/schema/mutation/update_update_channel_test.exs +++ b/backend/test/edgehog_web/schema/mutation/update_update_channel_test.exs @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,7 +50,10 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateUpdateChannelTest do assert update_channel_data["id"] == id assert update_channel_data["name"] == "Updated name" assert update_channel_data["handle"] == "updated-handle" - assert [target_group_data] = update_channel_data["targetGroups"] + + assert [target_group_data] = + extract_nodes!(update_channel_data["targetGroups"]["edges"]) + assert target_group_data["id"] == target_group_id assert target_group_data["name"] == target_group.name assert target_group_data["handle"] == target_group.handle @@ -189,9 +192,13 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateUpdateChannelTest do name handle targetGroups { - id - name - handle + edges { + node { + id + name + handle + } + } } } } @@ -247,4 +254,8 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateUpdateChannelTest do id end + + defp extract_nodes!(data) do + Enum.map(data, &Map.fetch!(&1, "node")) + end end diff --git a/backend/test/edgehog_web/schema/query/update_channel_test.exs b/backend/test/edgehog_web/schema/query/update_channel_test.exs index bff591d95..43efdac32 100644 --- a/backend/test/edgehog_web/schema/query/update_channel_test.exs +++ b/backend/test/edgehog_web/schema/query/update_channel_test.exs @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelTest do assert update_channel_data["handle"] == update_channel.handle assert update_channel_data["name"] == update_channel.name - assert [response_group] = update_channel_data["targetGroups"] + assert [response_group] = extract_nodes!(update_channel_data["targetGroups"]["edges"]) assert response_group["handle"] == target_group.handle assert response_group["name"] == target_group.name end @@ -57,8 +57,12 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelTest do handle name targetGroups { - name - handle + edges { + node { + name + handle + } + } } } } @@ -96,4 +100,8 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelTest do id end + + defp extract_nodes!(data) do + Enum.map(data, &Map.fetch!(&1, "node")) + end end diff --git a/backend/test/edgehog_web/schema/query/update_channels_test.exs b/backend/test/edgehog_web/schema/query/update_channels_test.exs index 67e6aa69d..df57f8f75 100644 --- a/backend/test/edgehog_web/schema/query/update_channels_test.exs +++ b/backend/test/edgehog_web/schema/query/update_channels_test.exs @@ -1,7 +1,7 @@ # # This file is part of Edgehog. # -# Copyright 2023-2024 SECO Mind Srl +# Copyright 2023 - 2025 SECO Mind Srl # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,12 +36,16 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelsTest do test "returns update channels if present", %{tenant: tenant, target_group: target_group} do update_channel = update_channel_fixture(target_group_ids: [target_group.id], tenant: tenant) - [update_channel_data] = [tenant: tenant] |> update_channels_query() |> extract_result!() + [update_channel_data] = + [tenant: tenant] |> update_channels_query() |> extract_result!() |> extract_nodes!() assert update_channel_data["id"] == AshGraphql.Resource.encode_relay_id(update_channel) assert update_channel_data["handle"] == update_channel.handle assert update_channel_data["name"] == update_channel.name - assert [target_group_data] = update_channel_data["targetGroups"] + + assert [target_group_data] = + extract_nodes!(update_channel_data["targetGroups"]["edges"]) + assert target_group_data["id"] == AshGraphql.Resource.encode_relay_id(target_group) assert target_group_data["handle"] == target_group.handle assert target_group_data["name"] == target_group.name @@ -52,13 +56,21 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelsTest do default_document = """ query { updateChannels { - id - handle - name - targetGroups { - id - name - handle + edges { + node { + id + handle + name + targetGroups { + edges { + node { + id + name + handle + } + } + } + } } } } @@ -73,7 +85,9 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelsTest do defp extract_result!(result) do assert %{ data: %{ - "updateChannels" => update_channels + "updateChannels" => %{ + "edges" => update_channels + } } } = result @@ -83,4 +97,8 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelsTest do update_channels end + + defp extract_nodes!(data) do + Enum.map(data, &Map.fetch!(&1, "node")) + end end