2020-12-02 18:07:15 +13:00
|
|
|
defmodule AshGraphql.Test.Schema do
|
2020-12-02 18:55:25 +13:00
|
|
|
@moduledoc false
|
|
|
|
|
2020-12-02 18:07:15 +13:00
|
|
|
use Absinthe.Schema
|
|
|
|
|
2024-05-24 04:11:28 +12:00
|
|
|
@domains [AshGraphql.Test.Domain, AshGraphql.Test.OtherDomain]
|
2020-12-02 18:07:15 +13:00
|
|
|
|
2024-08-17 06:35:21 +12:00
|
|
|
use AshGraphql, domains: @domains, generate_sdl_file: "priv/schema.graphql"
|
2020-12-02 18:07:15 +13:00
|
|
|
|
2023-10-16 00:09:30 +13:00
|
|
|
alias AshGraphql.Test.Post
|
|
|
|
|
|
|
|
require Ash.Query
|
|
|
|
|
2022-11-01 06:07:15 +13:00
|
|
|
query do
|
|
|
|
end
|
|
|
|
|
2022-11-02 14:58:41 +13:00
|
|
|
mutation do
|
|
|
|
end
|
|
|
|
|
2021-03-29 05:30:28 +13:00
|
|
|
object :foo do
|
|
|
|
field(:foo, :string)
|
|
|
|
field(:bar, :string)
|
|
|
|
end
|
|
|
|
|
|
|
|
input_object :foo_input do
|
|
|
|
field(:foo, non_null(:string))
|
|
|
|
field(:bar, non_null(:string))
|
|
|
|
end
|
|
|
|
|
2021-03-29 08:46:23 +13:00
|
|
|
enum :status do
|
|
|
|
value(:open, description: "The post is open")
|
|
|
|
value(:closed, description: "The post is closed")
|
|
|
|
end
|
2023-10-16 00:09:30 +13:00
|
|
|
|
|
|
|
subscription do
|
2023-10-28 01:50:51 +13:00
|
|
|
field :subscribable_created, :subscribable do
|
2023-10-16 00:09:30 +13:00
|
|
|
config(fn
|
|
|
|
_args, %{context: %{actor: %{id: user_id}}} ->
|
2023-10-28 01:50:51 +13:00
|
|
|
{:ok, topic: "subscribable:created", context_id: "user/#{user_id}"}
|
2023-10-16 00:09:30 +13:00
|
|
|
|
|
|
|
_args, _context ->
|
|
|
|
{:error, :unauthorized}
|
|
|
|
end)
|
|
|
|
|
|
|
|
resolve(fn args, _, resolution ->
|
|
|
|
# loads all the data you need
|
|
|
|
AshGraphql.Subscription.query_for_subscription(
|
|
|
|
Post,
|
|
|
|
Api,
|
|
|
|
resolution
|
|
|
|
)
|
|
|
|
|> Ash.Query.filter(id == ^args.id)
|
|
|
|
|> Ash.read(actor: resolution.context.current_user)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
2020-12-02 18:07:15 +13:00
|
|
|
end
|