-
Notifications
You must be signed in to change notification settings - Fork 4
/
schema.ex
37 lines (28 loc) · 877 Bytes
/
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
defmodule InventoryWeb.Schema do
use Absinthe.Schema
use Absinthe.Federation.Schema
link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@extends", "@external"])
query do
extends()
end
mutation do
field :decrement_inventory, :string do
arg(:upc, non_null(:string))
arg(:amount, :integer, default_value: 1)
resolve(&resolve_decrement_inventory/2)
end
end
object :product do
key_fields("upc")
extends()
field :upc, non_null(:string) do
external()
end
field(:in_stock, :boolean) do
resolve(&resolve_in_stock_for_product/3)
end
end
defp resolve_in_stock_for_product(%{upc: _upc} = _product, _args, _ctx), do: {:ok, true}
defp resolve_decrement_inventory(%{upc: upc, amount: amount}, _res),
do: {:ok, "Decremented the inventory for UPC #{upc} by #{amount}"}
end