Last active
September 27, 2016 22:26
-
-
Save robertkowalski/80190137314664cb9b904a18298686ac 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
handle_graphql(Req) -> | |
Res = 'Elixir.Chttpd.Graphql':run(), | |
io:format("~p", [Res]), | |
send_json(Req, {[ | |
{res, "Res"} | |
]}). |
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 Chttpd.Graphql do | |
def run() do | |
doc = """ | |
{ | |
item(id: "foo") { | |
name | |
} | |
} | |
""" | |
Absinthe.run(Chttpd.Schema, variables: %{"id" => "foo"}) | |
end | |
end |
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 Chttpd.Schema do | |
use Absinthe.Schema | |
@fake_db %{ | |
"foo" => %{id: "foo", name: "Foo", value: 4}, | |
"bar" => %{id: "bar", name: "Bar", value: 5} | |
} | |
query do | |
@desc "Get an item by ID" | |
field :item, type: :item do | |
@desc "The ID of the item" | |
arg :id, :id | |
resolve fn %{id: id}, _ -> | |
{:ok, Map.get(@fake_db, id)} | |
end | |
end | |
end | |
@desc "A valuable item" | |
object :item do | |
field :id, :id | |
field :name, :string, description: "The item's name" | |
field :value, :integer, description: "Recently appraised value" | |
end | |
end |
Author
robertkowalski
commented
Sep 27, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment