diff --git a/mix.exs b/mix.exs index e89e263..e564dcb 100644 --- a/mix.exs +++ b/mix.exs @@ -138,7 +138,7 @@ defmodule AshGraphql.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ash, ash_version("~> 3.0")}, + {:ash, ash_version("~> 3.0 and >= 3.1.3")}, {:absinthe_plug, "~> 1.4"}, {:absinthe, "~> 1.7"}, {:jason, "~> 1.2"}, diff --git a/mix.lock b/mix.lock index 5471c58..f37da40 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{ "absinthe": {:hex, :absinthe, "1.7.7", "ecbf4e9b21372dda271c79bb43dded3583b4f080348c5e68d9b5445e790ff17e", [:mix], [{:dataloader, "~> 1.0.0 or ~> 2.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", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:opentelemetry_process_propagator, "~> 0.2.1 or ~> 0.3", [hex: :opentelemetry_process_propagator, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2145519828bcb7c8621b72d7af2bcff88b01cba2774583c40ebd867e1d336ff6"}, "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"}, - "ash": {:hex, :ash, "3.1.2", "be3d955dc59c3d8314d0768cb9652ccb353f3ee1b7f48390220bddbb980065a6", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, "~> 0.2.12", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, ">= 0.8.1 and < 1.0.0-0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.7 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f9109e31583112ec3869a248d79796034c65ab332726d0c0025fe7f2200dd373"}, + "ash": {:hex, :ash, "3.1.3", "c5c65e18107247df4857951fa546e720c6e2ef0afde07ad0c2f523725a751eb2", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, "~> 0.2.12", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, ">= 0.8.1 and < 1.0.0-0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.7 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "530c04f32b2562352e48c92fab50bc837819c6cd3453c4fa9c9842b2e9d8483b"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"}, "comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"}, diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 5040e99..bf63158 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -371,11 +371,11 @@ defmodule AshGraphql.Test.Post do end read :best_post do - manual fn query, _, _ -> + manual(fn query, _, _ -> __MODULE__ |> Ash.Query.filter(best == true) |> Ash.read() - end + end) end read :best_post_arg do diff --git a/test/support/resources/user.ex b/test/support/resources/user.ex index 12ee075..81a1226 100644 --- a/test/support/resources/user.ex +++ b/test/support/resources/user.ex @@ -24,6 +24,11 @@ defmodule AshGraphql.Test.User do mutations do create :create_user, :create + update :authenticate_with_token, :authenticate_with_token do + identity false + read_action :get_by_token + end + destroy :delete_current_user, :destroy_current_user do identity false end @@ -54,6 +59,39 @@ defmodule AshGraphql.Test.User do end) end + update :authenticate_with_token do + require_atomic?(false) + metadata(:jwt, :string, allow_nil?: false) + + change(fn changeset, _struct -> + changeset + |> Ash.Changeset.after_action(fn changeset, customer -> + {:ok, Ash.Resource.put_metadata(customer, :jwt, "dummy-jwt")} + end) + end) + end + + read :get_by_token do + get?(true) + argument(:token, :string, allow_nil?: false) + + prepare(fn query, _ -> + token = query.arguments.token + + case token do + "valid-" <> _ -> + # For testing, we'll allow this action to return whatever customer is found + query + + _ -> + Ash.Query.after_action(query, fn _query, _results -> + error = %Ash.Error.Query.InvalidQuery{message: "test error"} + {:error, error} + end) + end + end) + end + destroy :destroy_current_user do filter(expr(id == ^actor(:id))) end diff --git a/test/update_test.exs b/test/update_test.exs index b84357d..4de597b 100644 --- a/test/update_test.exs +++ b/test/update_test.exs @@ -363,4 +363,28 @@ defmodule AshGraphql.UpdateTest do } = result end + + test "authenticateWithToken" do + _user = AshGraphql.Test.User + |> Ash.Changeset.for_create(:create, %{name: "Name"}) + |> Ash.create!(authorize?: false) + + resp = + """ + mutation AuthenticateWithToken($token: String!) { + authenticateWithToken(token: $token) { + result { + name + } + errors { + message + } + } + } + """ + |> Absinthe.run(AshGraphql.Test.Schema, variables: %{"token" => "invalid-token"}) + + + assert {:ok, %{data: %{"authenticateWithToken" => %{"errors" => [%{"message" => "test error"}], "result" => nil}}}} = resp + end end