Skip to content

Commit c09e7de

Browse files
committed
Fix: unify device creation and update subscriptions
Unified the GraphQL subscriptions for device creation and updates into a single subscription that handles both events. Absinthe subscriptions allow only one top-level field per operation. Signed-off-by: Osman Hadzic <osman.hadzic@secomind.com>
1 parent d3c8921 commit c09e7de

3 files changed

Lines changed: 8 additions & 19 deletions

File tree

backend/lib/edgehog/devices/device/device.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ defmodule Edgehog.Devices.Device do
6666
subscriptions do
6767
pubsub EdgehogWeb.Endpoint
6868

69-
subscribe :device_created do
70-
action_types :create
71-
end
72-
73-
subscribe :device_updated do
74-
action_types :update
69+
subscribe :device_changed do
70+
action_types [:create, :update]
7571
end
7672
end
7773
end

frontend/src/api/schema.graphql

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,12 +3967,9 @@ type HardwareType implements Node {
39673967
): HardwareTypePartNumberConnection!
39683968
}
39693969

3970-
type device_updated_result {
3971-
updated: Device
3972-
}
3973-
3974-
type device_created_result {
3970+
type device_changed_result {
39753971
created: Device
3972+
updated: Device
39763973
}
39773974

39783975
"The result of the :set_device_led_behavior mutation"
@@ -6520,14 +6517,10 @@ type RootMutationType {
65206517
}
65216518

65226519
type RootSubscriptionType {
6523-
deviceCreated(
6524-
"A filter to limit the results"
6525-
filter: DeviceFilterInput
6526-
): device_created_result
6527-
deviceUpdated(
6520+
deviceChanged(
65286521
"A filter to limit the results"
65296522
filter: DeviceFilterInput
6530-
): device_updated_result
6523+
): device_changed_result
65316524
}
65326525

65336526
"""

frontend/src/components/DevicesTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const DEVICES_TABLE_FRAGMENT = graphql`
8080

8181
const DEVICE_CREATED_SUBSCRIPTION = graphql`
8282
subscription DevicesTable_deviceCreated_Subscription {
83-
deviceCreated {
83+
deviceChanged {
8484
created {
8585
id
8686
deviceId
@@ -111,7 +111,7 @@ const DEVICE_CREATED_SUBSCRIPTION = graphql`
111111

112112
const DEVICE_UPDATED_SUBSCRIPTION = graphql`
113113
subscription DevicesTable_DeviceUpdated_Subscription {
114-
deviceUpdated {
114+
deviceChanged {
115115
updated {
116116
id
117117
deviceId

0 commit comments

Comments
 (0)