/
schema.ex
82 lines (68 loc) · 1.88 KB
/
schema.ex
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
74
75
76
77
78
79
80
81
82
defmodule ElixirBenchWeb.Schema do
use Absinthe.Schema
alias ElixirBenchWeb.Schema
alias ElixirBench.{Repos, Benchmarks}
import_types Absinthe.Type.Custom
import_types Schema.ContentTypes
query do
field :repos, list_of(:repo) do
resolve fn _, _ ->
{:ok, Repos.list_repos()}
end
end
field :repo, (:repo) do
arg :slug, non_null(:string)
resolve fn %{slug: slug}, _ ->
Repos.fetch_repo_by_slug(slug)
end
end
field :benchmark, non_null(:benchmark) do
arg :repo_slug, non_null(:string)
arg :name, non_null(:string)
resolve fn %{repo_slug: slug, name: name}, _ ->
with {:ok, repo_id} <- Repos.fetch_repo_id_by_slug(slug) do
Benchmarks.fetch_benchmark(repo_id, name)
end
end
end
field :measurement, non_null(:measurement) do
arg :id, non_null(:id)
resolve fn %{id: id}, _ ->
Benchmarks.fetch_measurement(id)
end
end
field :jobs, list_of(:job) do
resolve fn _, _ ->
{:ok, Benchmarks.list_jobs()}
end
end
field :job, non_null(:job) do
arg :id, non_null(:id)
resolve fn %{id: id}, _ ->
Benchmarks.fetch_job(id)
end
end
end
mutation do
field :schedule_job, type: :job do
arg :branch_name, non_null(:string)
arg :commit_sha, non_null(:string)
arg :repo_slug, non_null(:string)
resolve fn %{repo_slug: slug} = data, _ ->
with {:ok, repo} <- Repos.fetch_repo_by_slug(slug) do
Benchmarks.create_job(repo, data)
end
end
end
end
def context(ctx) do
loader =
Dataloader.new
|> Dataloader.add_source(Repos, Repos.data())
|> Dataloader.add_source(Benchmarks, Benchmarks.data())
Map.put(ctx, :loader, loader)
end
def plugins do
[Absinthe.Middleware.Dataloader] ++ Absinthe.Plugin.defaults()
end
end