-
Notifications
You must be signed in to change notification settings - Fork 9
/
.iex.exs
100 lines (80 loc) · 1.83 KB
/
.iex.exs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
alias Scoreboard.Games
defmodule LetMeSee do
@moduledoc """
Open N+1 in a terminal
Open regular in another terminal
mix ecto.reset
iex -S mix
cmd+r
LetMeSee.a_game()
LetMeSee.some_scores()
"""
alias Scoreboard.Repo
alias Scoreboard.Games.{Game, Player}
@game_id Game |> Repo.get_by!(name: "SuperVirus2") |> Map.get(:id)
@player_id Player |> Repo.get_by!(name: "Aaron") |> Map.get(:id)
IO.puts(
"\nAaron - This is your self from the past. Remember to reset the DB! mix ecto.reset then do setup\n"
)
def a_game() do
request = """
{
game(id: "#{@game_id}") {
id
name
}
}
"""
IO.puts("The Request:")
IO.puts(request)
result = Absinthe.run(request, ScoreboardWeb.Schema)
IO.puts("\nThe Result:")
result
end
def some_scores() do
request = """
{
game(id: "#{@game_id}") {
id
name
scores {
id
total
player {
id
name
}
}
}
}
"""
IO.puts("The Request:")
IO.puts(request)
{:ok, result} = Absinthe.run(request, ScoreboardWeb.Schema)
IO.inspect(result.data, label: "\nResults", limit: 5)
"Total Scores found: #{result |> get_in([:data, "game", "scores"]) |> length()}"
end
def scores_with_args() do
request = """
{
game(id: "#{@game_id}") {
id
name
scores(limit: 5, player_id: "#{@player_id}") {
id
total
player {
id
name
}
}
}
}
"""
IO.puts("The Request:")
IO.puts(request)
{:ok, result} = Absinthe.run(request, ScoreboardWeb.Schema)
IO.inspect(result.data, label: "\nResults", limit: 5)
"Aaron's Scores: #{result |> get_in([:data, "game", "scores"]) |> length()}"
end
end