towerops/lib/towerops_web/graphql/resolvers/integration.ex
Graham McIntire 532d88ffb9
perf: disable Req retry for faster error tests
- Add retry: false to VISP Client HTTP requests
- Add retry: false to ReleaseChecker GitHub API requests
- Remove unused Plug.Conn import from RemoteIpLogger
- Remove unused default parameter from req_get/2

Results:
- VISP sync test: 7007ms → 113ms (62x faster)
- ReleaseChecker test: 7004ms → 17ms (402x faster)
- UserResetPasswordLive test: 1495ms → 284ms (5x faster)

Req's default retry behavior (1s, 2s, 4s exponential backoff) was
causing 7-second delays for HTTP 500/503 error responses in tests.
For these clients, immediate failure is preferred over retries.
2026-03-10 16:19:31 -05:00

70 lines
2.4 KiB
Elixir

defmodule ToweropsWeb.GraphQL.Resolvers.Integration do
@moduledoc "GraphQL resolvers for integration management."
alias Towerops.Integrations
alias Towerops.Integrations.Integration
alias ToweropsWeb.GraphQL.Resolvers.Helpers
alias ToweropsWeb.ScopedResource
def list(_parent, _args, %{context: %{organization_id: org_id}}) do
integrations = Integrations.list_integrations(org_id)
{:ok, integrations}
end
def list(_parent, _args, _resolution), do: Helpers.authentication_error()
def create(_parent, %{input: input}, %{context: %{organization_id: org_id}}) do
attrs = Map.new(input, fn {k, v} -> {k, v} end)
case Integrations.create_integration(org_id, attrs) do
{:ok, integration} -> {:ok, integration}
{:error, changeset} -> {:error, Helpers.format_changeset_errors(changeset)}
end
end
def create(_parent, _args, _resolution), do: Helpers.authentication_error()
def update(_parent, %{id: id, input: input}, %{context: %{organization_id: org_id}}) do
case ScopedResource.fetch(Integration, id, org_id) do
{:ok, integration} ->
attrs = Map.new(input, fn {k, v} -> {k, v} end)
case Integrations.update_integration(integration, attrs) do
{:ok, updated} -> {:ok, updated}
{:error, changeset} -> {:error, Helpers.format_changeset_errors(changeset)}
end
_ ->
{:error, "Integration not found"}
end
end
def update(_parent, _args, _resolution), do: Helpers.authentication_error()
def delete(_parent, %{id: id}, %{context: %{organization_id: org_id}}) do
case ScopedResource.fetch(Integration, id, org_id) do
{:ok, integration} ->
case Integrations.delete_integration(integration) do
{:ok, _} -> {:ok, %{success: true, message: "Integration deleted"}}
{:error, _} -> {:ok, %{success: false, message: "Could not delete integration"}}
end
_ ->
{:error, "Integration not found"}
end
end
def delete(_parent, _args, _resolution), do: Helpers.authentication_error()
def test_connection(_parent, %{id: id}, %{context: %{organization_id: org_id}}) do
case ScopedResource.fetch(Integration, id, org_id) do
{:ok, integration} ->
{:ok, %{success: true, message: "Connection OK (#{integration.provider})"}}
_ ->
{:error, "Integration not found"}
end
end
def test_connection(_parent, _args, _resolution), do: Helpers.authentication_error()
end