From af879ec84d901fd8d01c1a7942af4d1e5a50c5fc Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 23 Aug 2025 08:25:09 +1000 Subject: [PATCH] graphql fix --- server/api_server/graphql_endpoint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/api_server/graphql_endpoint.py b/server/api_server/graphql_endpoint.py index f4dc053b..572c56ec 100755 --- a/server/api_server/graphql_endpoint.py +++ b/server/api_server/graphql_endpoint.py @@ -113,7 +113,6 @@ class Query(ObjectType): try: with open(folder + 'table_devices.json', 'r') as f: devices_data = json.load(f)["data"] - total_count = len(devices_data) except (FileNotFoundError, json.JSONDecodeError) as e: mylog('none', f'[graphql_schema] Error loading devices data: {e}') return DeviceResult(devices=[], count=0) @@ -127,6 +126,8 @@ class Query(ObjectType): mylog('trace', f'[graphql_schema] devices_data: {devices_data}') + # initialize total_count + total_count = len(devices_data) # Apply sorting if options are provided if options: @@ -222,7 +223,7 @@ class Query(ObjectType): 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) # Then apply pagination @@ -233,6 +234,7 @@ class Query(ObjectType): # Convert dict objects to Device instances to enable field resolution devices = [Device(**device) for device in devices_data] + return DeviceResult(devices=devices, count=total_count)