-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathschema.ex
More file actions
55 lines (41 loc) · 1.08 KB
/
schema.ex
File metadata and controls
55 lines (41 loc) · 1.08 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
defmodule BlogWeb.Schema do
use Absinthe.Schema
import_types Absinthe.Type.Custom
import_types BlogWeb.Schema.AccountTypes
import_types BlogWeb.Schema.ContentTypes
alias BlogWeb.Resolvers
query do
@desc "Get all posts"
field :posts, list_of(:post) do
resolve &Resolvers.Content.list_posts/3
end
@desc "Get a user of the blog"
field :user, :user do
arg :id, non_null(:id)
resolve &Resolvers.Accounts.find_user/3
end
end
mutation do
@desc "Create a post"
field :create_post, :post do
arg :title, non_null(:string)
arg :body, non_null(:string)
arg :published_at, :naive_datetime
resolve &Resolvers.Content.create_post/3
end
@desc "Create a user"
field :create_user, :user do
arg :name, non_null(:string)
arg :contact, non_null(:contact_input)
arg :password, non_null(:string)
resolve &Resolvers.Accounts.create_user/3
end
end
subscription do
field :new_post, :post do
config fn _args, _info ->
{:ok, topic: "*"}
end
end
end
end