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.
This commit is contained in:
parent
6b2de4a114
commit
c01f638d3a
2 changed files with 13 additions and 3 deletions
|
|
@ -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}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue