mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
graphql fix
This commit is contained in:
@@ -113,7 +113,6 @@ class Query(ObjectType):
|
|||||||
try:
|
try:
|
||||||
with open(folder + 'table_devices.json', 'r') as f:
|
with open(folder + 'table_devices.json', 'r') as f:
|
||||||
devices_data = json.load(f)["data"]
|
devices_data = json.load(f)["data"]
|
||||||
total_count = len(devices_data)
|
|
||||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
mylog('none', f'[graphql_schema] Error loading devices data: {e}')
|
mylog('none', f'[graphql_schema] Error loading devices data: {e}')
|
||||||
return DeviceResult(devices=[], count=0)
|
return DeviceResult(devices=[], count=0)
|
||||||
@@ -127,6 +126,8 @@ class Query(ObjectType):
|
|||||||
|
|
||||||
mylog('trace', f'[graphql_schema] devices_data: {devices_data}')
|
mylog('trace', f'[graphql_schema] devices_data: {devices_data}')
|
||||||
|
|
||||||
|
# initialize total_count
|
||||||
|
total_count = len(devices_data)
|
||||||
|
|
||||||
# Apply sorting if options are provided
|
# Apply sorting if options are provided
|
||||||
if options:
|
if options:
|
||||||
@@ -222,7 +223,7 @@ class Query(ObjectType):
|
|||||||
reverse=(sort_option.order.lower() == "desc")
|
reverse=(sort_option.order.lower() == "desc")
|
||||||
)
|
)
|
||||||
|
|
||||||
# capture total count after all the filtering and searching
|
# capture total count after all the filtering and searching, BEFORE pagination
|
||||||
total_count = len(devices_data)
|
total_count = len(devices_data)
|
||||||
|
|
||||||
# Then apply pagination
|
# Then apply pagination
|
||||||
@@ -234,6 +235,7 @@ class Query(ObjectType):
|
|||||||
# Convert dict objects to Device instances to enable field resolution
|
# Convert dict objects to Device instances to enable field resolution
|
||||||
devices = [Device(**device) for device in devices_data]
|
devices = [Device(**device) for device in devices_data]
|
||||||
|
|
||||||
|
|
||||||
return DeviceResult(devices=devices, count=total_count)
|
return DeviceResult(devices=devices, count=total_count)
|
||||||
|
|
||||||
# --- SETTINGS ---
|
# --- SETTINGS ---
|
||||||
|
|||||||
Reference in New Issue
Block a user