Skip to content

Commit

Permalink
Merge pull request #787 from lusergit/feat/device_group_ssp
Browse files Browse the repository at this point in the history
feat!(pagination): device_groups pagination
  • Loading branch information
davidebriani authored Jan 10, 2025
2 parents bec7548 + dd63f86 commit 9f82653
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
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

0 comments on commit 9f82653

Please sign in to comment.