Created
February 18, 2017 05:48
-
-
Save bruce/42114a233a0beff431c55c2793bf1800 to your computer and use it in GitHub Desktop.
Simplistic viewer example
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.