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): update_channel relay #791

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
5 changes: 3 additions & 2 deletions backend/lib/edgehog/update_campaigns/update_campaigns.ex
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,9 +213,13 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do
name
handle
targetGroups {
id
name
handle
edges {
node {
id
name
handle
}
}
}
}
}
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -189,9 +192,13 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateUpdateChannelTest do
name
handle
targetGroups {
id
name
handle
edges {
node {
id
name
handle
}
}
}
}
}
Expand Down Expand Up @@ -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
16 changes: 12 additions & 4 deletions backend/test/edgehog_web/schema/query/update_channel_test.exs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -57,8 +57,12 @@ defmodule EdgehogWeb.Schema.Query.UpdateChannelTest do
handle
name
targetGroups {
name
handle
edges {
node {
name
handle
}
}
}
}
}
Expand Down Expand Up @@ -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
40 changes: 29 additions & 11 deletions backend/test/edgehog_web/schema/query/update_channels_test.exs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
}
}
}
}
Expand All @@ -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

Expand All @@ -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
Loading