From c01f638d3af00d783bbf347ae5345d4770cbe392 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 13 Feb 2026 13:44:58 -0600 Subject: [PATCH] fix: use valid graphql query for gaiia connection test the viewer query doesn't exist in gaiia's schema, causing a 400 validation error. use a minimal accounts query instead. also handle 400 responses with graphql errors properly. --- lib/towerops/gaiia/client.ex | 7 +++++-- test/towerops/gaiia/client_test.exs | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/towerops/gaiia/client.ex b/lib/towerops/gaiia/client.ex index 1d469f13..25ea3e68 100644 --- a/lib/towerops/gaiia/client.ex +++ b/lib/towerops/gaiia/client.ex @@ -202,9 +202,9 @@ defmodule Towerops.Gaiia.Client do # --- Queries --- - @doc "Test the connection to Gaiia by running a simple viewer query." + @doc "Test the connection to Gaiia by fetching a single account." def test_connection(api_key, opts \\ []) do - case query(api_key, "{ viewer { id } }", %{}, opts) do + case query(api_key, "{ accounts(first: 1) { edges { node { id } } } }", %{}, opts) do {:ok, _data} -> {:ok, %{}} {:error, reason} -> {:error, reason} end @@ -239,6 +239,9 @@ defmodule Towerops.Gaiia.Client do {:ok, %{status: status, body: %{"errors" => errors}}} when status in 200..299 -> {:error, {:graphql_errors, errors}} + {:ok, %{status: 400, body: %{"errors" => errors}}} -> + {:error, {:graphql_errors, errors}} + {:ok, %{status: 401}} -> {:error, :unauthorized} diff --git a/test/towerops/gaiia/client_test.exs b/test/towerops/gaiia/client_test.exs index 3e6d57b2..0836edff 100644 --- a/test/towerops/gaiia/client_test.exs +++ b/test/towerops/gaiia/client_test.exs @@ -6,7 +6,14 @@ defmodule Towerops.Gaiia.ClientTest do describe "test_connection/2" do test "returns ok on successful connection" do Req.Test.stub(Client, fn conn -> - Req.Test.json(conn, %{"data" => %{"viewer" => %{"id" => "user-1"}}}) + Req.Test.json(conn, %{ + "data" => %{ + "accounts" => %{ + "edges" => [], + "pageInfo" => %{"hasNextPage" => false, "endCursor" => nil} + } + } + }) end) assert {:ok, %{}} = Client.test_connection("test-key")