defmodule ToweropsWeb.GraphQLDocsController do @moduledoc "Controller for GraphQL API documentation page." use ToweropsWeb, :controller alias Towerops.ApiTokens def index(conn, _params) do sample_token = case conn.assigns[:current_scope] do %{user: user, organization: org} when not is_nil(user) and not is_nil(org) -> tokens = ApiTokens.list_organization_api_tokens(org.id) if Enum.empty?(tokens) do "your-api-token-here (create one in your organization settings)" else token = List.first(tokens) "your-api-token-here (use: #{token.name})" end _ -> "YOUR_API_TOKEN" end render(conn, :index, sample_token: sample_token) end end