-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathschema.ex
More file actions
73 lines (58 loc) · 1.81 KB
/
schema.ex
File metadata and controls
73 lines (58 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
#
# SPDX-License-Identifier: MIT
defmodule AshGraphql.Test.Schema do
@moduledoc false
use Absinthe.Schema
@domains [
AshGraphql.Test.Domain,
AshGraphql.Test.OtherDomain,
AshGraphql.Test.RequireActorDomain
]
use AshGraphql, domains: @domains, generate_sdl_file: "priv/schema.graphql"
def middleware(middleware, _field, %Absinthe.Type.Object{identifier: identifier})
when identifier in [:query, :mutation, :subscription] do
middleware ++ [AshGraphql.MetaMiddleware]
end
def middleware(middleware, _field, _object) do
middleware
end
query do
field :custom_get_post, :post do
arg(:id, non_null(:id))
resolve(fn %{id: post_id}, resolution ->
with {:ok, post} when not is_nil(post) <- Ash.get(AshGraphql.Test.Post, post_id) do
post
|> AshGraphql.load_fields(AshGraphql.Test.Post, resolution)
end
|> AshGraphql.handle_errors(AshGraphql.Test.Post, resolution)
end)
end
field :custom_get_post_query, :post do
arg(:id, non_null(:id))
resolve(fn %{id: post_id}, resolution ->
AshGraphql.Test.Post
|> Ash.Query.do_filter(id: post_id)
|> AshGraphql.load_fields_on_query(resolution)
|> Ash.read_one(not_found_error?: true)
|> AshGraphql.handle_errors(AshGraphql.Test.Post, resolution)
end)
end
end
mutation do
end
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
enum :status do
value(:open, description: "The post is open")
value(:closed, description: "The post is closed")
end
subscription do
end
end