Skip to content

Instantly share code, notes, and snippets.

@neektza
Last active October 31, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neektza/67d081ee88099b2e9310be5b25432a5e to your computer and use it in GitHub Desktop.
Save neektza/67d081ee88099b2e9310be5b25432a5e to your computer and use it in GitHub Desktop.
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