Skip to content

Instantly share code, notes, and snippets.

@bruce
Created February 18, 2017 05:48
Show Gist options
  • Save bruce/42114a233a0beff431c55c2793bf1800 to your computer and use it in GitHub Desktop.
Save bruce/42114a233a0beff431c55c2793bf1800 to your computer and use it in GitHub Desktop.
Simplistic viewer example
defmodule MyApp.Schema do
use Absinthe.Schema
object :user do
# Define your user type
end
query do
field :viewer, :user do
resolve &resolve_viewer/3
end
end
def resolve_viewer(_, _, %{context: %{current_user: user}}) do
{:ok, user}
end
def resolve_viewer(_, _, _) do
{:ok, nil}
end
end
@bruce
Copy link
Author

bruce commented Feb 18, 2017

See http://absinthe-graphql.org/guides/context-and-authentication/#context-and-plugs to see an example of how to authenticate a user and put the user into the context for Absinthe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment