Skip to content

Commit 0a826bd

Browse files
committed
basic matching
1 parent 9f6a11e commit 0a826bd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/plate_slate_web/schema.ex

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
defmodule PlateSlateWeb.Schema do
22
use Absinthe.Schema
3-
# also see Absinthe.Schema.Notation
3+
4+
import Ecto.Query
5+
alias PlateSlate.{Menu, Repo}
46

57
query do
68
field :menu_items, list_of(:menu_item) do
7-
resolve fn _, _, _ ->
8-
schema = PlateSlate.Menu.Item
9-
{:ok, PlateSlate.Repo.all(schema)}
9+
arg :matching, :string
10+
11+
resolve fn
12+
_, %{matching: term}, _ ->
13+
items =
14+
Menu.Item
15+
|> where([i], ilike(i.name, ^"%#{term}%"))
16+
|> Repo.all
17+
{:ok, items}
18+
19+
_, _, _ ->
20+
items =
21+
Menu.Item
22+
|> Repo.all
23+
{:ok, items}
1024
end
1125
end
1226
end

0 commit comments

Comments
 (0)