fix graphql query

This commit is contained in:
Emil Lerch 2025-12-09 12:47:13 -08:00
parent 5375feda51
commit 7849c5456b
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -132,9 +132,13 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
\\}
;
// Remove newlines for JSON payload
const query_clean = try std.mem.replaceOwned(u8, allocator, query, "\n", " ");
defer allocator.free(query_clean);
const body = try std.fmt.allocPrint(allocator,
\\{{"query":"{s}","variables":{{"email":"{s}"}}}}
, .{ query, username });
, .{ query_clean, username });
defer allocator.free(body);
const uri = try std.Uri.parse(appsync_url);
@ -209,9 +213,20 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se
\\}
;
var query_clean_buf: [query.len]u8 = undefined;
// Remove newlines for JSON payload
const query_replacements = std.mem.replace(
u8,
query,
"\n",
" ",
query_clean_buf[0..],
);
const query_clean = query_clean_buf[0 .. query.len - ("\n".len * query_replacements)];
const body = try std.fmt.allocPrint(allocator,
\\{{"query":"{s}","variables":{{"heater_serial_number":"{s}"}}}}
, .{ query, serial_number });
, .{ query_clean, serial_number });
defer allocator.free(body);
const uri = try std.Uri.parse(appsync_url);