From 7ff85c7a757c599a2d56b2053f66c13086c046c2 Mon Sep 17 00:00:00 2001 From: RyanMoret Date: Sat, 22 Mar 2025 12:03:18 -0500 Subject: [PATCH] serialize hashes and arrays in variables --- lib/sanity/http/where.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/sanity/http/where.rb b/lib/sanity/http/where.rb index 5b625a2..42e89db 100644 --- a/lib/sanity/http/where.rb +++ b/lib/sanity/http/where.rb @@ -41,7 +41,7 @@ def query_and_variables else {}.tap do |hash| variables.each do |key, value| - hash["$#{key}"] = "\"#{value}\"" + hash["$#{key}"] = serialize_variable_value(value) end end end.merge(query: groq_query) @@ -56,6 +56,17 @@ def request_body query_and_variables.to_json end + + def serialize_variable_value(value) + case value + when String + "\"#{value}\"" + when Array, Hash + value.to_json + else + value.to_s + end + end end end end