Last active
October 10, 2015 01:36
-
-
Save 1player/751e9aa965995162e5db to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Character do | |
use GraphQL.ObjectInterface | |
field :id, null: false | |
field :name | |
field :friends, type: List.of(Character) | |
field :appearsIn, type: List.of(Episode) | |
end | |
defmodule Human do | |
use GraphQL.Object, deriving: Character | |
field :homePlanet | |
end | |
defmodule Droid do | |
use GraphQL.Object, deriving: Character | |
field :primaryFunction | |
end | |
defmodule Schema do | |
use GraphQL.Schema | |
field :hero, type: Character do | |
argument :episode, description: "foo" | |
resolve %{episode: episode} do | |
getHero(episode) | |
end | |
resolve do | |
getHero(1000) | |
end | |
end | |
field :human, type: Human do | |
argument :id, description: "id of the human", null: false | |
resolve %{id: id} do | |
getHuman(id) | |
end | |
end | |
field :droid, type: Droid do | |
argument :id, description: "id of the droid", null: false | |
resolve %{id: id} do | |
getDroid(id) | |
end | |
end | |
@humans [ | |
"1000": %Human{ | |
id: "1000", | |
name: "Luke Skywalker", | |
friends: ["1002", "1003", "2000", "2001"], | |
appearsIn: [4, 5, 6], | |
homePlanet: "Tatooine", | |
}, | |
"1001": %Human{ | |
id: "1001", | |
name: "Darth Vader", | |
friends: [ "1004" ], | |
appearsIn: [ 4, 5, 6 ], | |
homePlanet: "Tatooine", | |
}, | |
[ ... ] | |
] | |
@droids [ ... ] | |
defp getHero(5), do: @humans["1000"] | |
defp getHero(_), do: @droids["2001"] | |
defp getHuman(id), do: @humans[id] | |
defp getDroid(id), do: @droids[id] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment