Skip to content

Commit 74b6d4b

Browse files
committed
fix: add use Absinthe.Phoenix.Socket in endpoints in installer
1 parent 99fec98 commit 74b6d4b

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

lib/igniter.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,13 @@ if Code.ensure_loaded?(Igniter) do
260260

261261
igniter =
262262
Enum.reduce(endpoints_that_need_parser, igniter, fn endpoint, igniter ->
263-
Igniter.Project.Module.find_and_update_module!(igniter, endpoint, fn zipper ->
263+
igniter
264+
|> Igniter.Project.Module.find_and_update_module!(endpoint, fn zipper ->
265+
with {:ok, zipper} <- Igniter.Code.Module.move_to_use(zipper, Phoenix.Endpoint) do
266+
{:ok, Igniter.Code.Common.add_code(zipper, "use Absinthe.Phoenix.Endpoint")}
267+
end
268+
end)
269+
|> Igniter.Project.Module.find_and_update_module!(endpoint, fn zipper ->
264270
case Igniter.Code.Function.move_to_function_call_in_current_scope(
265271
zipper,
266272
:plug,

test/mix/tasks/ash_graphql_install_test.exs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,16 @@ defmodule Mix.Tasks.AshGraphqlInstallTest do
106106
end
107107

108108
test "adds the socket and parser to the endpoint", %{igniter: igniter} do
109-
assert_has_patch(igniter, "lib/test_web/endpoint.ex", ~S'''
110-
...|
111-
17 17 | )
112-
18 18 |
113-
19 + | socket("/ws/gql", TestWeb.GraphqlSocket,
114-
20 + | websocket: true,
115-
21 + | longpoll: true
116-
22 + | )
117-
23 + |
118-
19 24 | # Serve at "/" the static files from "priv/static" directory.
119-
20 25 | #
120-
...|
121-
46 51 |
122-
47 52 | plug(Plug.Parsers,
123-
48 - | parsers: [:urlencoded, :multipart, :json],
124-
53 + | parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
125-
49 54 | pass: ["*/*"],
126-
50 55 | json_decoder: Phoenix.json_library()
127-
109+
igniter
110+
|> assert_has_patch("lib/test_web/endpoint.ex", ~S'''
111+
+ | socket("/ws/gql", TestWeb.GraphqlSocket,
112+
+ | websocket: true,
113+
+ | longpoll: true
114+
+ | )
115+
+ |
116+
''')
117+
|> assert_has_patch("lib/test_web/endpoint.ex", ~S'''
118+
+ | use Absinthe.Phoenix.Endpoint
128119
''')
129120
end
130121

0 commit comments

Comments
 (0)