Last active
October 31, 2019 10:09
-
-
Save neektza/67d081ee88099b2e9310be5b25432a5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule GostPlatformWeb.GraphQL.Schema do | |
use Absinthe.Schema | |
use Absinthe.Schema.Notation | |
use Absinthe.Relay.Schema, :modern | |
use Absinthe.Relay.Schema.Notation, :modern | |
alias GostPlatform.{Vessel, Fleet} | |
@fleets %{ | |
"123" => %Fleet{id: "123", name: "Star fleet", area: "Alpha quadrant"}, | |
"321" => %Fleet{id: "321", name: "US Navy", area: "All the earth oceans"} | |
} | |
@vessels %{ | |
"456" => %Vessel{id: "456", name: "USS Enterprise", designation: "NCC-1701"}, | |
"654" => %Vessel{id: "654", name: "USS George Washington", designation: "CVN-73"} | |
} | |
node object(:vessel) do | |
field(:name, :string) | |
field(:designation, :string) | |
end | |
node object(:fleet) do | |
field(:name, :string) | |
field(:area, :string) | |
end | |
node interface do | |
resolve_type(fn | |
(%{designation: _}, _res) -> | |
:vessel | |
(%{area: _}, _res) -> | |
:fleet | |
(qux, _res) -> | |
nil | |
end) | |
end | |
query do | |
node field do | |
resolve fn | |
(%{type: :vessel, id: id}, _res) -> | |
{:ok, Map.get(@vessels, id)} | |
(%{type: :fleet, id: id}, _res) -> | |
{:ok, Map.get(@fleets, id)} | |
(obj, _res) -> | |
{:ok, nil} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment