ash_graphql/test/support/resources/movie.ex
Davide Briani 18d4e1b010
test: add tests on paginated relationships (#177)
Add tests to verify that relationships can be queried on the results of
GraphQL queries and mutations.

Querying paginated relationships on the result of deletions doesn't
correctly work yet.
Indeed, Ash currently queries relationships using a lateral join but
after the resource deletion has happened, so it looks like nothing is
related.

Signed-off-by: Davide Briani <davide@briani.dev>
2024-06-11 09:49:05 -04:00

55 lines
1.2 KiB
Elixir

defmodule AshGraphql.Test.Movie do
@moduledoc false
use Ash.Resource,
domain: AshGraphql.Test.Domain,
data_layer: Ash.DataLayer.Ets,
extensions: [AshGraphql.Resource]
graphql do
type(:movie)
paginate_relationship_with(actors: :relay, reviews: :offset, awards: :keyset)
queries do
get :get_movie, :read
list :get_movies, :read, paginate_with: nil
end
mutations do
create :create_movie, :create_with_actors
update :update_movie, :update
destroy :destroy_movie, :destroy
end
end
actions do
default_accept(:*)
defaults([:create, :read, :update, :destroy])
create :create_with_actors do
argument :actor_ids, {:array, :uuid} do
allow_nil? false
constraints(min_length: 1)
end
change(manage_relationship(:actor_ids, :actors, type: :append))
end
end
attributes do
uuid_primary_key(:id)
attribute(:title, :string, public?: true)
end
relationships do
many_to_many(:actors, AshGraphql.Test.Actor,
through: AshGraphql.Test.MovieActor,
public?: true
)
has_many(:reviews, AshGraphql.Test.Review, public?: true)
has_many(:awards, AshGraphql.Test.Award, public?: true)
end
end