Skip to content

Commit

Permalink
Cleanup Absinthe configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gcauchon committed Feb 9, 2023
1 parent ab43831 commit f5171d3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 39 deletions.
3 changes: 2 additions & 1 deletion lib/elixir_boilerplate/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule ElixirBoilerplate.Application do
ElixirBoilerplateWeb.Telemetry,
ElixirBoilerplate.Repo,
{Phoenix.PubSub, [name: ElixirBoilerplate.PubSub, adapter: Phoenix.PubSub.PG2]},
ElixirBoilerplateWeb.Endpoint
ElixirBoilerplateWeb.Endpoint,
{Absinthe.Subscription, ElixirBoilerplateWeb.Endpoint}
]

opts = [strategy: :one_for_one, name: ElixirBoilerplate.Supervisor]
Expand Down
27 changes: 0 additions & 27 deletions lib/elixir_boilerplate_graphql/router.ex

This file was deleted.

1 change: 1 addition & 0 deletions lib/elixir_boilerplate_graphql/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule ElixirBoilerplateGraphQL.Schema do
# first mutation.
#
# mutation do
# import_fields(:application_mutations)
# end

def context(context) do
Expand Down
13 changes: 4 additions & 9 deletions lib/elixir_boilerplate_web/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
defmodule ElixirBoilerplateWeb.Endpoint do
use Sentry.PlugCapture

use Phoenix.Endpoint, otp_app: :elixir_boilerplate

use Absinthe.Phoenix.Endpoint

alias Plug.Conn

@plug_ssl Plug.SSL.init(rewrite_on: [:x_forwarded_proto])
Expand Down Expand Up @@ -49,10 +52,8 @@ defmodule ElixirBoilerplateWeb.Endpoint do
plug(Plug.MethodOverride)
plug(Plug.Head)

plug(ElixirBoilerplateWeb.Plugs.Security)
# plug(ElixirBoilerplateWeb.Plugs.Security)
# plug(ElixirBoilerplateHealth.Router)
# plug(ElixirBoilerplateGraphQL.Router)
# plug(:halt_if_sent)
plug(ElixirBoilerplateWeb.Router)

@doc """
Expand Down Expand Up @@ -119,10 +120,4 @@ defmodule ElixirBoilerplateWeb.Endpoint do
conn
end
end

# Splitting routers in separate modules has a negative side effect:
# Phoenix.Router does not check the Plug.Conn state and tries to match the
# route even if it was already handled/sent by another router.
defp halt_if_sent(%{state: :sent, halted: false} = conn, _opts), do: halt(conn)
defp halt_if_sent(conn, _opts), do: conn
end
23 changes: 21 additions & 2 deletions lib/elixir_boilerplate_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ElixirBoilerplateWeb.Router do
use Phoenix.Router

pipeline :browser do
plug(:accepts, ["html", "json"])
plug(:accepts, ~w[html json])

plug(:session)
plug(:fetch_session)
Expand All @@ -13,12 +13,31 @@ defmodule ElixirBoilerplateWeb.Router do
plug(:put_root_layout, {ElixirBoilerplateWeb.Layouts, :root})
end

pipeline :api do
plug(:accepts, ~w[json])

plug(:session)
end

scope "/", ElixirBoilerplateWeb do
pipe_through(:browser)
pipe_through :browser

get("/", PageController, :home)
end

scope "/api" do
pipe_through :api

forward("/graphql", Absinthe.Plug, schema: ElixirBoilerplateGraphQL.Schema)

if Mix.env() == :dev do
forward("/graphiql", Absinthe.Plug.GraphiQL,
schema: ElixirBoilerplateGraphQL.Schema,
socket: ElixirBoilerplateWeb.Socket
)
end
end

# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir_boilerplate_web/socket.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule ElixirBoilerplateWeb.Socket do
use Phoenix.Socket

use Absinthe.Phoenix.Socket, schema: ElixirBoilerplateGraphQL.Schema

def connect(_params, socket) do
{:ok, socket}
end
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ defmodule ElixirBoilerplate.Mixfile do
# GraphQL
{:absinthe, "~> 1.7"},
{:absinthe_plug, "~> 1.5"},
{:absinthe_phoenix, "~> 2.0"},
{:dataloader, "~> 1.0"},
{:absinthe_error_payload, "~> 1.1"},

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%{
"absinthe": {:hex, :absinthe, "1.7.1", "aca6f64994f0914628429ddbdfbf24212747b51780dae189dd98909da911757b", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.2.2 or ~> 1.3.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c0c4dbd93881fa3bfbad255608234b104b877c2a901850c1fe8c53b408a72a57"},
"absinthe_error_payload": {:hex, :absinthe_error_payload, "1.1.4", "502ff239148c8deaac028ddb600d6502d5be68d24fece0c93f4c3cf7e74c1a4d", [:make, :mix], [{:absinthe, "~> 1.3", [hex: :absinthe, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm", "9e262ef2fd4a2c644075e0cdde2573b1f713c0676ab905c8640eaa8a882b2aca"},
"absinthe_phoenix": {:hex, :absinthe_phoenix, "2.0.2", "e607b438db900049b9b3760f8ecd0591017a46122fffed7057bf6989020992b5", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:absinthe_plug, "~> 1.5", [hex: :absinthe_plug, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.5", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.13 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}], "hexpm", "d36918925c380dc7d2ed7d039c9a3b4182ec36723f7417a68745ade5aab22f8d"},
"absinthe_plug": {:hex, :absinthe_plug, "1.5.8", "38d230641ba9dca8f72f1fed2dfc8abd53b3907d1996363da32434ab6ee5d6ab", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bbb04176647b735828861e7b2705465e53e2cf54ccf5a73ddd1ebd855f996e5a"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
"castore": {:hex, :castore, "1.0.0", "c25cd0794c054ebe6908a86820c8b92b5695814479ec95eeff35192720b71eec", [:mix], [], "hexpm", "577d0e855983a97ca1dfa33cbb8a3b6ece6767397ffb4861514343b078fc284b"},
Expand Down

0 comments on commit f5171d3

Please sign in to comment.