Skip to content

Instantly share code, notes, and snippets.

@bruce
Created January 4, 2017 20:51
Show Gist options
  • Select an option

  • Save bruce/9bec46f02e0292484744935c6ff98d66 to your computer and use it in GitHub Desktop.

Select an option

Save bruce/9bec46f02e0292484744935c6ff98d66 to your computer and use it in GitHub Desktop.
Comparing absinthe schema definition to graphql-elixir schema definition
defmodule TestSchema do
use Absinthe.Schema
query do
@desc "A Greeting"
field :greeting, :string do
@desc "The name of who you'd like to greet"
arg :name, :string
resolve &greeting/3
end
end
defp greeting(_, %{name: name}, _), do: {:ok, "Hello, #{name}!"}
defp greeting(_, _, _), do: {:ok, "Hello, world!"}
end
defmodule TestSchema do
def schema do
%GraphQL.Schema{
query: %GraphQL.Type.ObjectType{
name: "RootQueryType",
fields: %{
greeting: %{
type: %GraphQL.Type.String{},
resolve: &TestSchema.greeting/3,
description: "Greeting",
args: %{
name: %{type: %GraphQL.Type.String{}, description: "The name of who you'd like to greet."},
}
}
}
}
}
end
def greeting(_, %{name: name}, _), do: "Hello, #{name}!"
def greeting(_, _, _), do: "Hello, world!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment