diff --git a/backend/lib/edgehog/update_campaigns/update_campaign/update_campaign.ex b/backend/lib/edgehog/update_campaigns/update_campaign/update_campaign.ex index 0111f8b81..99cc59e9e 100644 --- a/backend/lib/edgehog/update_campaigns/update_campaign/update_campaign.ex +++ b/backend/lib/edgehog/update_campaigns/update_campaign/update_campaign.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.UpdateCampaign do graphql do type :update_campaign + + paginate_relationship_with update_targets: :relay end actions do diff --git a/backend/lib/edgehog/update_campaigns/update_campaigns.ex b/backend/lib/edgehog/update_campaigns/update_campaigns.ex index f08d189c6..b85d55bf9 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. @@ -41,7 +41,8 @@ defmodule Edgehog.UpdateCampaigns do list UpdateCampaign, :update_campaigns, :read do description "Returns a list of update campaigns." - paginate_with nil + paginate_with :keyset + relay? true end get UpdateChannel, :update_channel, :read do diff --git a/backend/test/edgehog_web/schema/mutation/create_update_campaign_test.exs b/backend/test/edgehog_web/schema/mutation/create_update_campaign_test.exs index e9dfad4b6..bbb9c74a5 100644 --- a/backend/test/edgehog_web/schema/mutation/create_update_campaign_test.exs +++ b/backend/test/edgehog_web/schema/mutation/create_update_campaign_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. @@ -62,7 +62,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateCampaignTest do assert update_campaign_data["updateChannel"]["id"] == update_channel_id assert update_campaign_data["updateChannel"]["name"] == update_channel.name assert update_campaign_data["updateChannel"]["handle"] == update_channel.handle - assert [target_data] = update_campaign_data["updateTargets"] + assert [target_data] = extract_nodes!(update_campaign_data["updateTargets"]["edges"]) assert target_data["status"] == "IDLE" assert target_data["device"]["id"] == AshGraphql.Resource.encode_relay_id(device) @@ -81,7 +81,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateCampaignTest do assert update_campaign_data["name"] == "My Update Campaign" assert update_campaign_data["status"] == "FINISHED" assert update_campaign_data["outcome"] == "SUCCESS" - assert update_campaign_data["updateTargets"] == [] + assert update_campaign_data["updateTargets"]["edges"] == [] # Check that no executor got started update_campaign = fetch_update_campaign_from_graphql_id!(tenant, update_campaign_data["id"]) @@ -353,9 +353,13 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateCampaignTest do handle } updateTargets { - status - device { - id + edges { + node { + status + device { + id + } + } } } } @@ -461,4 +465,8 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateCampaignTest do [{pid, _}] -> {:ok, pid} end 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_campaign_test.exs b/backend/test/edgehog_web/schema/query/update_campaign_test.exs index 3d1f4921a..e58953d46 100644 --- a/backend/test/edgehog_web/schema/query/update_campaign_test.exs +++ b/backend/test/edgehog_web/schema/query/update_campaign_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. @@ -92,7 +92,7 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignTest do assert response_rollout_mechanism["forceDowngrade"] == update_campaign.rollout_mechanism.value.force_downgrade - assert [target] = update_campaign_data["updateTargets"] + assert [target] = extract_nodes!(update_campaign_data["updateTargets"]["edges"]) assert target["status"] == "IDLE" assert target["device"]["id"] == AshGraphql.Resource.encode_relay_id(device) @@ -120,13 +120,17 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignTest do query ($id: ID!) { updateCampaign(id: $id) { updateTargets { - id - status - retryCount - latestAttempt - completionTimestamp - otaOperation { - id + edges { + node { + id + status + retryCount + latestAttempt + completionTimestamp + otaOperation { + id + } + } } } } @@ -138,7 +142,7 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignTest do |> update_campaign_query() |> extract_result!() - assert [update_target] = update_campaign_data["updateTargets"] + assert [update_target] = extract_nodes!(update_campaign_data["updateTargets"]["edges"]) assert update_target["id"] == AshGraphql.Resource.encode_relay_id(target) assert update_target["status"] == "SUCCESSFUL" @@ -264,9 +268,13 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignTest do handle } updateTargets { - status - device { - id + edges { + node { + status + device { + id + } + } } } } @@ -305,4 +313,8 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignTest 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_campaigns_test.exs b/backend/test/edgehog_web/schema/query/update_campaigns_test.exs index a15493087..d817311ff 100644 --- a/backend/test/edgehog_web/schema/query/update_campaigns_test.exs +++ b/backend/test/edgehog_web/schema/query/update_campaigns_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. @@ -65,7 +65,8 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do tenant: tenant ) - [update_campaign_data] = [tenant: tenant] |> update_campaigns_query() |> extract_result!() + [update_campaign_data] = + [tenant: tenant] |> update_campaigns_query() |> extract_result!() |> extract_nodes!() assert update_campaign_data["name"] == update_campaign.name assert update_campaign_data["status"] == "IDLE" @@ -91,7 +92,7 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do assert response_rollout_mechanism["forceDowngrade"] == update_campaign.rollout_mechanism.value.force_downgrade - assert [target] = update_campaign_data["updateTargets"] + assert [target] = extract_nodes!(update_campaign_data["updateTargets"]["edges"]) assert target["status"] == "IDLE" assert target["device"]["id"] == AshGraphql.Resource.encode_relay_id(device) @@ -104,14 +105,22 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do document = """ query { updateCampaigns { - updateTargets { - id - status - retryCount - latestAttempt - completionTimestamp - otaOperation { - id + edges { + node { + updateTargets { + edges { + node { + id + status + retryCount + latestAttempt + completionTimestamp + otaOperation { + id + } + } + } + } } } } @@ -119,9 +128,12 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do """ [update_campaign_data] = - [document: document, tenant: tenant] |> update_campaigns_query() |> extract_result!() + [document: document, tenant: tenant] + |> update_campaigns_query() + |> extract_result!() + |> extract_nodes!() - assert [update_target] = update_campaign_data["updateTargets"] + assert [update_target] = extract_nodes!(update_campaign_data["updateTargets"]["edges"]) assert update_target["id"] == AshGraphql.Resource.encode_relay_id(target) assert update_target["status"] == "FAILED" @@ -138,30 +150,38 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do default_document = """ query { updateCampaigns { - name - status - outcome - rolloutMechanism { - ... on PushRollout { - maxFailurePercentage - maxInProgressUpdates - otaRequestRetries - otaRequestTimeoutSeconds - forceDowngrade - } - } - baseImage { - version - url - } - updateChannel { - name - handle - } - updateTargets { - status - device { - id + edges { + node { + name + status + outcome + rolloutMechanism { + ... on PushRollout { + maxFailurePercentage + maxInProgressUpdates + otaRequestRetries + otaRequestTimeoutSeconds + forceDowngrade + } + } + baseImage { + version + url + } + updateChannel { + name + handle + } + updateTargets { + edges { + node { + status + device { + id + } + } + } + } } } } @@ -177,7 +197,9 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do defp extract_result!(result) do assert %{ data: %{ - "updateCampaigns" => update_campaigns + "updateCampaigns" => %{ + "edges" => update_campaigns + } } } = result @@ -187,4 +209,8 @@ defmodule EdgehogWeb.Schema.Query.UpdateCampaignsTest do update_campaigns end + + defp extract_nodes!(data) do + Enum.map(data, &Map.fetch!(&1, "node")) + end end