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): device_groups pagination #787

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
4 changes: 3 additions & 1 deletion backend/lib/edgehog/groups/device_group/device_group.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Edgehog.
#
# Copyright 2022-2024 SECO Mind Srl
# Copyright 2022-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 @@ -31,6 +31,8 @@ defmodule Edgehog.Groups.DeviceGroup do

graphql do
type :device_group

# TODO: paginate `device` relationship with relay
end

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

list DeviceGroup, :device_groups, :read do
description "Returns a list of device groups."
paginate_with nil
paginate_with :keyset
relay? true
end
end

Expand Down
33 changes: 22 additions & 11 deletions backend/test/edgehog_web/schema/query/device_groups_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Edgehog.
#
# Copyright 2022-2024 SECO Mind Srl
# Copyright 2022-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 @@ -38,6 +38,7 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do
[tenant: tenant, id: id]
|> device_groups_query()
|> extract_result!()
|> Enum.map(&Map.fetch!(&1, "node"))

assert result["id"] == id
assert result["name"] == fixture.name
Expand Down Expand Up @@ -71,9 +72,13 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do
document = """
query {
deviceGroups {
name
devices {
id
edges {
node {
name
devices {
id
}
}
}
}
}
Expand All @@ -88,7 +93,8 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do

foo_device_ids =
result
|> Enum.find(result, &(&1["name"] == "foo"))
|> Enum.find(result, &(&1["node"]["name"] == "foo"))
|> Map.fetch!("node")
|> Map.fetch!("devices")
|> Enum.map(& &1["id"])

Expand All @@ -99,7 +105,8 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do

bar_device_ids =
result
|> Enum.find(result, &(&1["name"] == "bar"))
|> Enum.find(result, &(&1["node"]["name"] == "bar"))
|> Map.fetch!("node")
|> Map.fetch!("devices")
|> Enum.map(& &1["id"])

Expand All @@ -114,10 +121,14 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do
default_document = """
query {
deviceGroups {
id
name
handle
selector
edges {
node {
id
name
handle
selector
}
}
}
}
"""
Expand All @@ -130,7 +141,7 @@ defmodule EdgehogWeb.Schema.Query.DeviceGroupsTest do
end

defp extract_result!(result) do
assert %{data: %{"deviceGroups" => device_groups}} = result
assert %{data: %{"deviceGroups" => %{"edges" => device_groups}}} = result
refute :errors in Map.keys(result)
assert device_groups != nil

Expand Down
Loading