Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/absinthe/plug/graphiql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ defmodule Absinthe.Plug.GraphiQL do
defp get_config_val(config, key, conn) do
case Map.get(config, key) do
{module, fun} when is_atom(fun) ->
Code.ensure_loaded(module)

case function_arity(module, fun) do
1 ->
apply(module, fun, [conn])
Expand Down
19 changes: 19 additions & 0 deletions test/lib/absinthe/graphiql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ defmodule Absinthe.Plug.GraphiQLTest do
)
end

test "default_url module is loaded" do
module = "Elixir.GraphiQLDefaultUrl" |> String.to_atom()

opts =
Absinthe.Plug.GraphiQL.init(
schema: TestSchema,
default_url: {module, :graphiql_default_url}
)

assert %{status: status, resp_body: body} =
conn(:get, "/")
|> plug_parser
|> put_req_header("accept", "text/html")
|> Absinthe.Plug.GraphiQL.call(opts)

assert 200 == status
assert String.contains?(body, "defaultUrl: '#{graphiql_default_url()}'")
end

test "socket_url option works a function of arity 0" do
opts =
Absinthe.Plug.GraphiQL.init(
Expand Down
3 changes: 3 additions & 0 deletions test/support/graphiql_default_url.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule GraphiQLDefaultUrl do
def graphiql_default_url(), do: "https://api.foobarbaz.test"
end